ASP文章自动分页

<%
’#######################
程序名: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(allline/pageline)+1 ’计算总页数
page=request("page")
if isempty(page) then
thispage=1
else
thispage=cint(page)
end if
response.write " "&title&" "&title&"
"
for i=0 to allline
if i+1>thispage*pageline-pageline and i response.write linenum(i) &"
" ’输出分页后的内容
end if
next
response.write chr(13)&"
"
response.write "

总共"&allline&"行 "&pagecount&"页 每页"&pageline&"行 "
for i=1 to pagecount
if thispage=i then
response.write i & " "
else
response.write ""&i&" " ’输出所有分页链接
end if
next
’---------------------主代码结束--------------------------
%>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值