Home >Backend Development >PHP Tutorial >Implement click statistics in static pages_PHP tutorial
Using the server-side method of generating static pages in an article publishing system can effectively reduce the load on the server, which is especially effective for high-traffic websites. But since the generated page is a static page, what will it look like when it is generated and how will it be displayed? How to display the number of times common articles have been read?
After consideration, the following solution can be used:
When generating a static page, an article id will be generated and stored in the database. Then when we make the article template, we can make an article based on the article id. The template contains the following statements:
Instructions:
Using the template When generating an article, perform pattern matching on "#articleId#" and replace it with the id number of the newly added article.
The counter.asp file is an asp file that implements counting
<%
''###################
''######Start#########
''BY Wang Xiangchao
''###################
dim articleId,sqlStr,hits
articleId=int(trim(request.querystring("articleId")))
sqlStr="update articles set hits=hits+1 where articleId=" & articleId
''Add 1 to the number of article hits
conn.execute(sqlStr)
''Read the number of article clicks
hits=conn.execute("select hits from articles where articleId=" & articleId)(0 )
%>
''Print out the number of article hits
document.write(<%=hits%>)