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