ASP easy to build counters

Source: Internet
Author: User
Tags count end sql trim access
Implementation of a number of methods, this article mainly introduces the use of database to achieve a simple counter!

' Save As Count.asp ' below

<%
Set conn=server.createobject ("ADODB. Connection ")
Conn. Open "Driver={microsoft Access driver (*.mdb)};d bq=" & Server.MapPath ("Count.mdb")
%>
<%on Error Resume next%>
<%sql= "Update count set Hit=hit+1%><%conn. Execute (SQL)%>
<%sql = "SELECT * from Count
Set Rs=conn.execute (SQL)
%>
<%
' Update weekly daily data
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 (Today ())-cint (year (lasthit))
P_month=cint (Month (now))-cint (month (lasthit))
P_day=cint (Today ())-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%") Dayhit times today to visit <%=rs ("%>"), visit <%=rs ("Weekhit")%> times this week, Total Access <%=rs ("hit")%> times </td> tr> ');
<%rs.close
Set rs=nothing%>

Build a database: Build a count of the MDB library, and then build a table count, in the table field

Hit Digital type

Dayhit Digital Type

Weekhit Digital Type

Lasthit Date Type



Related Article

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.