'下面存为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 日期型
静态:
在静态页面中显示文章被阅读的次数
在文章发布系统中采用服务器端生成静态页面的方法可以有效减轻服务器的负担,特别是对大流量网站非常有效。但是既然生成的是静态页面,生成时是什么样,显示就是什么样了,对于文章常见文章被阅读次数怎么显示呢?
经考虑,可用如下方案解决:
生成静态页面时会产生一个文章的id存到数据库中,那么我们在制作文章的模板的时候就可以在这个文章的id上做文章,文章模板包含以下语句:
<SCRIPT src="counter.asp?articleId=<%=#articleId#%>"></SCRIPT >
<b>说明:</b>
在利用模板生成文章时,把"#articleId#"进行模式匹配,替换为新添加的文章的id号。
counter.asp 文件为实现记数的asp文件
<%
'###################
'######开始#########
'BY 王向超
'###################
dim articleId,sqlStr,hits
articleId=int(trim(request.querystring("articleId")))
sqlStr="update articles set hits=hits+1 where articleId=" &articleId
'给文章点击数加1
conn.execute(sqlStr)
'读出文章点击数
hits=conn.execute("select hits from articles where articleId=" &articleId)(0)
%>
'打印出文章点击数
document.write(<%=hits%>)
<% if request.querystring("action")="delete" thenif Trim(Request.form("id"))="" then
FoundErr=True
Message=Message &"<li>请您选择要删除的信息!</li>"
else
call Del(cint(Trim(Request.form("id"))))
end if
if FoundErr=True then
call ErrMsg(Message)
end if
sub del(id)
sql = "select * from product where id ="&id
rs=server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,3
if not rs.eof then
rs.delete
rs.update
response.Write("<script>alert(""删除成功!"")window.location.href='index.asp'</script>")
set rs=nothing
response.end
else
FoundErr=True
Message="你要删除的ID不存在!"
end if
End Sub
end if
%>
<%set rs=server.createobject("adodb.recordset")
rs.open ("select info_list from mb"),conn,1,1
pencat=rs("info_list")
rs.close
tid=request("tid")
currentPage=cint(request("page"))
MaxPerPage=cint(request("MaxPerPage"))
'################ 读取标题 等.. 开始 ################
rs.open "select * from infotype where id="&tid,conn,1,1
if not rs.eof then
ts=rs("ts")
TN=split(rs("tname"),"|")
TI=split(rs("ts"), ",")
for i = 0 to ubound(TN)-1
if i=ubound(TN)-2 and ubound(TN)>1 then
TTY_id=TI(i)
TTY_name=TN(i)
end if
all_type_top_id=TI(i)
all_type_name=TN(i)
thistype=thistype &"-><a href=""../info/"&TI(i)&"_1.htm"">"&TN(i)&"</a>"
thistitle=thistitle &" - "&TN(i)&""
next
end if
rs.close
sql="select * from infotype where ts like '"&ts&"%'"
rs.open sql,conn,1,1
if not rs.eof then
do while not rs.eof
sqqq=sqqq&""&rs("id")&", "
rs.MoveNext
loop
end if
rs.close
''########读取下级分类
rs.open "select * from infotype where tn="&tid&" order by id",conn,1,1
if NOT rs.EOF then
TTY="NO"
Tname=all_type_name
do while NOT rs.EOF
TTNN=split(rs("tname"),"|")(rs("tj")-1)
TXlist=TXlist&"<a href=""../info/"&rs("id")&"_1.htm""><font color=""#000000"">"&TTNN&"</font></a><br>"
rs.MoveNext
loop
end if
rs.close
if TTY_id<>"" and TTY<>"NO" then
rs.open "select * from infotype where tn="&TTY_id&" order by id",conn,1,1
if NOT rs.EOF then
Tname=TTY_name
do while NOT rs.EOF
TTNN=split(rs("tname"),"|")(rs("tj")-1)
TXlist=TXlist&"<a href=""../info/"&rs("id")&"_1.htm""><font color=""#000000"">"&TTNN&"</font></a><br>"
rs.MoveNext
loop
end if
rs.close
end if
''########读取本类top10
sql="select * from info where tid in("&sqqq&") order by hits desc"
rs.open sql,conn,1,1
if rs.eof then
Txtop="·还没有文章"
else
do while not rs.eof
h=h+1
Txtop=Txtop&"·<a href=""../info/"&rs("id")&".htm"">"&rs("title")&"</a><br>"
if h>=10 then exit do
rs.movenext
loop
h=0
end if
rs.close
'读取文章列表
sql="select * from info where tid in("&sqqq&") order by date desc"
rs.open sql,conn,1,1
if rs.eof then
lb=lb&"<tr><td width=""100%"" colspan=""3"">对不起! 暂时没有相关文章 @_@</td></tr>"
mpage=1
allshu=0
else
rs.pagesize=MaxPerPage '得到每页数
mpage=rs.pagecount '得到总页数
rs.move (currentPage-1)*MaxPerPage
allshu=rs.recordcount
h=0
do while not rs.eof
h=h+1
lb=lb&"<tr height=""22""><td width=""77%""><img border=""0"" src=""../images/d_2.gif"" width=""11"" height=""11"">["
set rs_type=server.CreateObject("ADODB.RecordSet")
rs_type.open "select * from infotype where id="&rs("tid"),conn,1,1
if not rs_type.EOF then
TN=split(rs_type("tname"),"|")
lb=lb&"<a href="""&rs("tid")&"_1.htm""><font color=""#000000"">"&TN(ubound(TN)-1)&"</font></a></FONT>"
end if
rs_type.close
lb=lb&"] <a href=""../info/"&rs("id")&".htm"">"&rs("title")&"</a></td>"
lb=lb&"<td width=""13%"" align=""center"">"&year(rs("date"))&"-"&month(rs("date"))&"-"&day(rs("date"))&"</td>"
lb=lb&"<td width=""10%"" align=""center"">"&rs("hits")&"</td></tr>"
lb=lb&"<tr><td width=""100%"" height=""1"" bgcolor=""#CCCCCC"" colspan=""3""></td></tr>"
if h>=MaxPerPage then exit do
rs.movenext
loop
end if
rs.close
set rs=nothing
conn.close
set conn=nothing
'#########读取页次
lb=lb&"<table border=""0"" width=""100%"" cellspacing=""0"" cellpadding=""0""><tr><td width=""15%"" nowrap>页次:<b>"&currentPage&"</b>/<b>"&mpage&"</b>每页<b>"&MaxPerPage&"</b>文章数<b>"&allshu&"</b></td><td width=""65%"" nowrap><p align=""center"">"
pageno=currentPage
if cint(pageno)>1 then
lb=lb&"<a href=../info/"&tid&"_1.htm title=""最前页"">"
end if
lb=lb&"<font face=""Webdings"">9</font></a> "
if cint(pageno)>1 then
lb=lb&"<a href=../info/"&tid&"_"&pageno-1&".htm title=""上一页"">"
end if
lb=lb&"<font face=""Webdings"">7</font></a>"
pp=cint(pageno)-2
if pp<1 then
pp=1
end if
for pno=pp to mpage
p=p+1
if pno*1=cint(pageno)*1 then
lb=lb&" <font color=""#FF0000"">["&pno&"]</font>"
else
lb=lb&" <a href=../info/"&tid&"_"&pno&".htm>["&pno&"]</a>"
end if
if p>=5 then exit for
next
lb=lb&" "
if cint(pageno)<mpage then
lb=lb&"<a href=../info/"&tid&"_"&pageno+1&".htm title=""下一页"">"
end if
lb=lb&"<font face=""Webdings"">8</font></a> "
if cint(pageno)<mpage then
lb=lb&"<a href=../info/"&tid&"_"&mpage&".htm title=""最后页"">"
end if
lb=lb&"<font face=""Webdings"">:</font></a></p></td><td width=""18%"" nowrap><table cellpadding=""0"" cellspacing=""0"">"
lb=lb&"<form onsubmit=""window.location=this.KKK2.options[this.KKK2.selectedIndex].valuereturn false"">"
lb=lb&"<tr><td nowrap>到<select name=""select"" onchange=""javascript:window.location.href=this.options[this.selectedIndex].value"">"
for i=1 to mpage
selected=""
if currentpage=i then
selected=" selected"
end if
lb=lb&"<option value=../info/"&tid&"_"&i&".htm"&selected&">"&i&"</option>"
next
lb=lb&"</select>页</td></td></tr></form></table></td></tr></table>"
'################ 读取完成 ################
pencat=replace(pencat,"T_TITLE",thistitle)
pencat=replace(pencat,"T_NAME",tname)
pencat=replace(pencat,"TXlist",txlist)
pencat=replace(pencat,"TXtop",Txtop)
pencat=replace(pencat,"T_LB",lb)
pencat=replace(pencat,"T_TXT",typetxt)
pencat=replace(pencat,"T_TYPE",thistype)
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(server.mappath("../info/"&tid&"_"&currentPage&".htm"))
fout.Write pencat
fout.close
'************** 生成HTML页 结束 ***************
%>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)