主题:  请教问题啊,各位前辈!计数问题!

我有BLOG了

职务:普通成员
等级:4
金币:16.8
发贴:2209
#12003/6/24 11:35:18
<%
sessionID = session.SessionID
timeout = 5
' set how long to keep this session in minute you can increase this number

Conn_String = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("count.mdb")
'Conn_String = "activeUser"
'set your DSN = "activeuser" is a better way because you need include this file to all your asp scripts.


Set ConnCount =Server.CreateObject("ADODB.Connection")
ConnCount.Open Conn_String

' delete session after timeout
aaa = dateadd("n", -timeout, now())
connCount.Execute ("delete * from count where postdate < #" & aaa & "#")


' keep sessionID
sql0 = "select sess from count where sess='" & sessionID & "'"
set rscheck = connCount.Execute (sql0)
if rscheck.eof then
sql = "insert into count (sess,postdate) values('" & sessionID & "', '" & now() & "')"
connCount.Execute (sql)
end if
rscheck.close
set rscheck = nothing

'count sessionID
sql2 = "select count(sess) from count"
set rs = connCount.Execute (sql2)
count = rs(0)
rs.close
set rs = nothing


sql3 = "select * from count"
set rspredel = connCount.Execute (sql3)
do until rspredel.eof
xxx=DateDiff("n", rspredel("postdate"), Now())
if xxx > timeout then
count = count-1
end if
rspredel.movenext
loop
rspredel.close
set rspredel = nothing

connCount.Close
set connCount = nothing

if count = 0 then
count = 1
end if
%>

document.write('当前<%=count%>人在线');


以上为一个计数器代码
这是复制别人的代码.......

能有前辈大体告诉我一下是什么愿意,让他不用引用 global.asa 这个文件来计算网站浏览人数的?????????



{ 在指尖上绽放的花朵 }

职务:普通成员
等级:5
金币:14.0
发贴:3209
#22003/6/24 16:18:51
<%
sessionID = session.SessionID
timeout = 5

Conn_String = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("count.mdb")
'Conn_String = "activeUser"
'set your DSN = "activeuser" is a better way because you need include this file to all your asp scripts.
Set ConnCount =Server.CreateObject("ADODB.Connection")
ConnCount.Open Conn_String

打开count.mdb,用来存储统计信息。

' delete session after timeout
aaa = dateadd("n", -timeout, now())
connCount.Execute ("delete * from count where postdate < #" & aaa & "#")

删除postdate和now()之间相差timeout的记录。

' keep sessionID
sql0 = "select sess from count where sess='" & sessionID & "'"
set rscheck = connCount.Execute (sql0)

选择表中sess = sessionID的部分

if rscheck.eof then
sql = "insert into count (sess,postdate) values('" & sessionID & "', '" & now() & "')"
connCount.Execute (sql)
end if
rscheck.close
set rscheck = nothing

如果没有符合条件的记录,则创建。


'count sessionID
sql2 = "select count(sess) from count"
set rs = connCount.Execute (sql2)
count = rs(0)
rs.close
set rs = nothing

读取count中共有多少sess记录,结果赋给count

sql3 = "select * from count"
set rspredel = connCount.Execute (sql3)
do until rspredel.eof
xxx=DateDiff("n", rspredel("postdate"), Now())
if xxx > timeout then
count = count-1
end if
rspredel.movenext
loop
rspredel.close
set rspredel = nothing

对于count中的每条记录执行如下操作~
如果postdate和now()之间相差多于timeout,则count变量减一。

connCount.Close
set connCount = nothing

if count = 0 then
count = 1
end if
%>

数据库关闭,做初始值。

document.write('当前<%=count%>人在线');

输出



我有BLOG了

职务:普通成员
等级:4
金币:16.8
发贴:2209
#32003/6/24 22:55:30
谢谢前辈帮助~

这2句有些不明白

aaa = dateadd("n", -timeout, now())
connCount.Execute ("delete * from count where postdate < #" & aaa & "#")

能详细的讲解一下每个参数吗???麻烦前辈了~


编辑历史:[这消息被仙鹤编辑过(编辑时间2003-06-24 23:04:12)]


{ 在指尖上绽放的花朵 }

职务:普通成员
等级:5
金币:14.0
发贴:3209
#42003/6/24 23:10:44
前辈真的不敢当。

如果在5d我都是前辈,那么没有人不是前辈了~

引用:
aaa = dateadd("n", -timeout, now())


获取前timeout分钟前的日期,存放在变量aaa里面。

引用:
connCount.Execute ("delete * from count where postdate < #" & aaa & "#")

删除所有count中postdate在时间aaa之前的记录。

编辑历史:[这消息被行者编辑过(编辑时间2003-06-24 23:11:17)]