How to easily create ASP counters

Source: Internet
Author: User

The following describes how to use a database to implement a simple counter.
'Save As count. asp
<%
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & server. mappath ("count. mdb ")
%>
<% On error resume next %>
<% SQL = "Update count set hit = hit + 1%> <% conn. Execute (SQL) %>
<% SQL = "select * from Count
Set rsw.conn.exe cute (SQL)
%>
<%
'Update daily data every week
Lasthit = RS ("lasthit ")
Tdate = year (now () & "-" & month (now () & "-" & Day (now ())
If trim (lasthit) = trim (tdate) then
SQL = "Update site set dayhit = dayhit + 1 where id =" & request ("ID ")
Conn. Execute (SQL)
'Response. Write "success"
Else
SQL = "Update site set dayhit = 1 where id =" & request ("ID ")
Conn. Execute (SQL)
'Response. Write "error"
End if
SQL = "Update site set lasthit = '" & tdate & "'where id =" & request ("ID ")
Conn. Execute (SQL)

 

P_year = CINT (Year (now ()-CINT (Year (lasthit ))
P_month = CINT (month (now ()-CINT (month (lasthit ))
P_day = CINT (Day (now ()-CINT (Day (lasthit ))
Period_time = (p_year * 12 + p_month) * 30 + p_day)
If CINT (period_time) = <CINT (7) then
SQL = "Update site set weekhit = weekhit + 1 where id =" & request ("ID ")
Conn. Execute (SQL)
Else
SQL = "Update site set weekhit = 1 where id =" & request ("ID ")
Conn. Execute (SQL)
End if
%>
Document. write ('<tr> <TD width = "100%"> today's visit <% = RS ("dayhit") %>, visit this week <% = RS ("weekhit ") %> times, total visits <% = RS ("hit") %> Times </TD> </tr> ');
<% Rs. Close
Set rs = nothing %>

'Use <script language = "javascript1.1" src = "count. asp"> </SCRIPT> to call it on the page to be counted.

Database creation: Create a count mdb database, and then create a table count. The table field is
Hit digital
Dayhit digital
Weekhit digital
Lasthit date type

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.