asp网络编程:如何轻松打造ASP计数器

  以下介绍用数据库实现简单计数器

  '下面存为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 rs=conn.execute(sql)

  %>

  <%

  '更新每周每日数据

  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%">今日访问<%=rs("dayhit")%>次,本周访问<%=rs("weekhit")%>次,总访问<%=rs("hit")%>次</td></tr>');

  <%rs.close

  set rs=nothing%>

  '用<script language="JavaScript1.1" src="count.asp"></script>在要统计的页面调用即可.

  建立数据库:建一个count的MDB库,再建一个表count,表中字段为

  hit 数字型

  dayhit 数字型

  weekhit 数字型

  lasthit 日期型

看了这篇文章相信你对“如何松打造ASP计数器”一定有所了解了,如果还有不懂的可以点击上海治疗阳痿医院程序给你解惑哦?

转载于:https://www.cnblogs.com/chaorenman/p/4086530.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值