ASP network programming: How to easily build an ASP counter

Source: Internet
Author: User

The following describes the implementation of simple counters with a database

' 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 (now ())-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) =

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 (' Today visit <%=rs ("Dayhit")%> times, this week visit <%=rs ("Weekhit")%> times, Total Access <%=rs ("hit")%> times tr> ');

<%rs.close

Set rs=nothing%>

' Use

Build a database: Build a Count MDB library, build a table count, and the table field

Hit Digital type

Dayhit Digital Type

Weekhit Digital Type

Lasthit Date Type

Read this article believe you on the "How to build ASP counter" must have some understanding, if there is not understand can click Shanghai Treatment Impotence Hospital procedures to give you doubts oh?

ASP network programming: How to easily build an ASP counter

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.