สร้างตัวนับ ASP ได้อย่างง่ายดาย
ผู้เขียน:Eve Cole
เวลาอัปเดต:2009-06-23 16:43:18
以下介绍用数据库实现简单计数器
'下的存为count.asp
-
ตั้งค่า conn=Server.CreateObject("ADODB.Connection")
conn.Open "driver={ไดรเวอร์ Microsoft Access (*.mdb)};dbq="& Server.MapPath("count.mdb")
-
<%เมื่อเกิดข้อผิดพลาดต่อดำเนินการต่อ%>
<%sql="ชุดการนับการอัปเดต hit=hit+1%><%conn.Execute(sql)%>
<%sql = "เลือก * จากการนับ
ตั้งค่า rs=conn.execute(sql)
-
-
'更新每周每日数据
Lasthit=rs("lasthit")
tdate=ปี(ตอนนี้()) & "-" & เดือน (ตอนนี้()) & "-" & วัน (ตอนนี้())
ถ้า trim(lasthit)=trim(tdate) แล้ว
sql="อัปเดตชุดไซต์ dayhit=dayhit+1 โดยที่ id="&request("id")
conn.ดำเนินการ(sql)
' ตอบกลับเขียนว่า "ความสำเร็จ"
อื่น
sql = "อัปเดตชุดไซต์ dayhit = 1 โดยที่ id = "&request ("id")
conn.ดำเนินการ(sql)
' ตอบกลับเขียน "ข้อผิดพลาด"
สิ้นสุดถ้า
sql="อัปเดตชุดไซต์ Lasthit='"&tdate&"' โดยที่ ID="&request("id")
conn.ดำเนินการ(sql)
p_year=CInt(ปี(ตอนนี้()))-CInt(ปี(lasthit))
p_month=CInt(เดือน(ตอนนี้()))-CInt(เดือน(lasthit))
p_day=CInt(วัน(ตอนนี้()))-CInt(วัน(lasthit))
period_time=((p_year*12+p_month)*30+p_day)
ถ้า cint(term_time)=<cint(7) แล้ว
sql="อัปเดตชุดไซต์ weekhit=weekhit+1 โดยที่ id="&request("id")
conn.ดำเนินการ(sql)
อื่น
sql = "อัปเดตชุดไซต์ weekhit = 1 โดยที่ id = "&request ("id")
conn.ดำเนินการ(sql)
สิ้นสุดถ้า
-
document.write('<tr><td width="100%">今日访问<%=rs("dayhit")%>次,本周访问<%=rs("weekhit")%>次,总访问<%=rs("hit")%>次</td></tr>');
<%rs.ปิด
ตั้งค่า rs=nothing%>
'用<script language="JavaScript1.1" src="count.asp"></script>在要统计的页的调用即可.
建立数据库:建一个count的MDB库,再建一个表count,表中字段为
กด 数字型
dayhit 数字型
weekhit 数字型
สุดท้าย 日期型