|
在文章發(fā)布系統(tǒng)中采用服務(wù)器端生成靜態(tài)頁面的方法可以有效減輕服務(wù)器的負(fù)擔(dān),特別是對大流量網(wǎng)站非常有效。但是既然生成的是靜態(tài)頁面,生成時(shí)是什么樣,顯示就是什么樣了,對于文章常見文章被閱讀次數(shù)怎么顯示呢?
經(jīng)考慮,可用如下方案解決: 生成靜態(tài)頁面時(shí)會產(chǎn)生一個(gè)文章的id存到數(shù)據(jù)庫中,那么我們在制作文章的模板的時(shí)候就可以在這個(gè)文章的id上做文章,文章模板包含以下語句: <SCRIPT src="counter.asp?articleId=<%=#articleId#%>"></SCRIPT >
說明:
在利用模板生成文章時(shí),把"#articleId#"進(jìn)行模式匹配,替換為新添加的文章的id號。
counter.asp 文件為實(shí)現(xiàn)記數(shù)的asp文件
<%
'###################
'######開始#########
'BY 王向超
'###################
dim articleId,sqlStr,hits
articleId=int(trim(request.querystring("articleId")))
sqlStr="update articles set hits=hits+1 where articleId=" & articleId
'給文章點(diǎn)擊數(shù)加1
conn.execute(sqlStr)
'讀出文章點(diǎn)擊數(shù)
hits=conn.execute("select hits from articles where articleId=" & articleId)(0)
%>
'打印出文章點(diǎn)擊數(shù)
document.write(<%=hits%>)
|