• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

长文章自动实现分页功能

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 14次 | 进入软件测试论坛讨论

领测软件测试网 为了版美观,有时需要将一编较长的文章分页来显示,这时只好将文章分多次存入数据库,极不方便
本人见过多种自动分页代码,感觉上不是很理想
偶的思路是统计文章的所有行数,按指定行数输出显示内容并生成分页导航
如有不足之处望写信告诉作者

演示地址: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
‘’---------------------主代码结束--------------------------
%>

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网