長文章自動完成分頁技巧
發表時間:2024-06-04 來源:明輝站整理相關軟件相關文章人氣:
[摘要]為了版美觀,有時需要將一編較長的文章分頁來顯示,這時只好將文章分多次存入數據庫,極不方便 本人見過多種自動分頁代碼,感覺上不是很理想 偶的思路是統計文章的所有行數,按指定行數輸出顯示內容并生成分頁導航 如有不足之處望寫信告訴作者 演示地址:http://mail-1.fz169.net/wh/sy...
為了版美觀,有時需要將一編較長的文章分頁來顯示,這時只好將文章分多次存入數據庫,極不方便
本人見過多種自動分頁代碼,感覺上不是很理想
偶的思路是統計文章的所有行數,按指定行數輸出顯示內容并生成分頁導航
如有不足之處望寫信告訴作者
演示地址:http://mail-1.fz169.net/wh/sys/page/
<%
'#######################
'程序名:ASP文章自動分頁
'編 寫: 網 海 求 生 者
' Q Q:54883661 E-mail:
'
[email protected] '#######################
'連接數據庫:
on error resume next
dim conn,connstr,dbpath
dbpath=server.mappath("web.mdb") '數據庫文件名
set conn=server.createobject("adodb.connection")
connstr="driver={microsoft access driver (*.mdb)};dbq="&dbpath&";"
conn.open connstr
if err.number<>0 then
response.write err.description
err.clear
response.end
end if
sub connclose()
conn.close()
set conn=nothing
end sub
'讀取數據:
dim rs,sql,conntent,title,id
id=1'trim(request("id")) '上頁傳來的ID值,為了調試方便此ID值臨時賦為1
set rs=server.createobject("adodb.recordset")
sql="select * from news where id="&cint(id)
rs.open sql,conn,1,1
if not (rs.eof and rs.bof) then
content=rs("content") '讀取內容
title=rs("title") '讀取標題
end if
if err.number<>0 then
response.write err.description
err.clear
response.end
end if
rs.close
set rs=nothing
call connclose()
'分頁處理部分:
'---------------------主代碼開始--------------------------
dim page,pagecount,thispage,linenum,allline
const pageline=10 '每頁顯示10行
linenum=split(content,"<br>") '本例為計算字符串<br>標記的個數
allline=ubound(linenum)+1 '全文<br>(換行標記)總數
pagecount=int(allline\pageline)+1 '計算總頁數
page=request("page")
if isempty(page) then
thispage=1
else
thispage=cint(page)
end if
response.write "<title>"&title&"</title><b>"&title&"</b><hr>"
for i=0 to allline
if i+1>thispage*pageline-pageline and i<thispage*pageline then
response.write linenum(i) &"<br>" '輸出分頁后的內容
end if
next
response.write chr(13)&"<hr>"
response.write "<p align='center'>總共"&allline&"行 "&pagecount&"頁 每頁"&pageline&"行 "
for i=1 to pagecount
if thispage=i then
response.write i & " "
else
response.write "<a href='?page="&i&"&id="&id&"'>"&i&"</a> " '輸出所有分頁鏈接
end if
next
'---------------------主代碼結束--------------------------
%>