asp統(tǒng)計(jì)信息代碼實(shí)例/文章每日、每周、每月、總訪(fǎng)問(wèn)量的方法
<%
'//hittime 日期型:獲得上次訪(fǎng)問(wèn)時(shí)間
'//hits 數(shù)字型:獲得總瀏覽量
'//hitsday 數(shù)字型:獲得今天瀏覽量
'//hitsweeks 數(shù)字型:獲得本周瀏覽量
'//hitmonths 數(shù)字型:獲得本月瀏覽量
'數(shù)據(jù)庫(kù)中 添加這5個(gè)字段。
set rs1=server.CreateObject("adodb.recordset")
rs1.open "select * from qwbmnewssss where id=26",conn,1,3
if rs1.eof and rs1.bof then
response.write "erry"
else
hittime = rs1("hittime") '獲得上次訪(fǎng)問(wèn)時(shí)間
dim dayNow,monthNow,weeknow
dayNow = day(date()) '現(xiàn)在幾號(hào)
monthNow = month(date()) '現(xiàn)在幾月
weekNow = weekday(date()) '現(xiàn)在星期幾 0為星期天
rs1("hits") = rs1("hits") + 1 '總瀏覽次數(shù) + 1
if datediff("d",hittime,now()) = 0 then '比較最后訪(fǎng)問(wèn)日期與現(xiàn)在的時(shí)間 天數(shù)
rs1("hitsday") = rs1("hitsday") + 1 '今天的瀏覽量 + 1
else
rs1("hitsday") = 1 '今天的瀏覽量 = 1
end if
if monthNow = month(hittime) then
rs1("hitmonths") = rs1("hitmonths") + 1 '本月的瀏覽量 + 1
else
rs1("hitmonths") = 1 '本月的瀏覽量 + 1
end if
if datediff("d",hittime,now()) > 6 then '在處理星期的期的時(shí)候有一個(gè)問(wèn)題,如果上一個(gè)時(shí)間是星期五,下一次訪(fǎng)問(wèn)是下個(gè)星期的星期二,記錄還是疊加。
rs1("hitsweeks") = 1
else
if weekNow <> 1 then
rs1("hitsweeks") = rs1("hitsweeks") + 1
else
weekNowss = weekday(hittime) '上次訪(fǎng)問(wèn)的星期幾
if weekNow = weekNowss then
rs1("hitsweeks") = rs1("hitsweeks") + 1
else
rs1("hitsweeks") = 1
end if
end if
end if
rs1("hittime") = now() '更新最后的訪(fǎng)問(wèn)題意
rs1.update
%>
時(shí)間比較:<%=datediff("d",hittime,now())%><br />
當(dāng)前時(shí)間:<%=now()%><br />
最后點(diǎn)擊時(shí)間:<%=hittime%><br />
當(dāng)前天:<%=dayNow%><br />
當(dāng)前月:<%=monthNow%><br />
當(dāng)前周:<%=weekNow%><br />
總共瀏覽量:<%=rs1("hits")%><br />
今天訪(fǎng)問(wèn)量:<%=rs1("hitsday")%><br />
星期訪(fǎng)問(wèn)量:<%=rs1("hitsweeks")%><br />
當(dāng)月訪(fǎng)問(wèn)量:<%=rs1("hitmonths")%><br />
<%
end if
rs1.close
set rs1=nothing
%>
關(guān)鍵詞:asp
閱讀本文后您有什么感想? 已有 人給出評(píng)價(jià)!
- 0
- 0
- 0
- 0
- 0
- 0