一聚教程网:一个值得你收藏的教程网站

热门教程

长文章自动实现分页功能

时间:2022-07-02 23:51:05 编辑:袖梨 来源:一聚教程网

为了版美观,有时需要将一编较长的文章分页来显示,这时只好将文章分多次存入数据库,极不方便
本人见过多种自动分页代码,感觉上不是很理想
偶的思路是统计文章的所有行数,按指定行数输出显示内容并生成分页导航
如有不足之处望写信告诉作者
演示地址:http://mail-1.fz169.net/wh/sys/page/
<%
'#######################
'程序名:ASP文章自动分页
'编 写: 网 海 求 生 者
' Q Q:54883661 E-mail:
' wuyingke5155@163.com
'#######################
'连接数据库:
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,"
") '本例为计算字符串
标记的个数
allline=ubound(linenum)+1 '全文
(换行标记)总数
pagecount=int(alllinepageline)+1 '计算总页数
page=request("page")

热门栏目