[原创]2005最快ASP分页演示下载
演示地址:http://demo-asp.com/demo/works_list.asp
下载地址及使用说明:
http://www.joekoe.com/forum_view.asp?forum_id=9&view_id=54405
100分分给头两个 提供在线测试用户 最好能做1000w记录的在线测试
需要说明的是
更新完数据后 先轻空 cache文件夹
每隔一千页 初始化 一次,可以又第一个访问者完成 或者站长亲自完成
下载后直接浏览page_list.asp文件即可。
问题点数:100、回复次数:51Top
1 楼baikaishui_0825(baikaishui)回复于 2005-01-31 11:25:05 得分 0
沙发Top
2 楼diya(风火浪|努力学习.NET/C#)回复于 2005-01-31 11:26:02 得分 0
顶Top
3 楼injoo(寒云)回复于 2005-01-31 11:27:58 得分 0
?????Top
4 楼baikaishui_0825(baikaishui)回复于 2005-01-31 11:28:40 得分 0
还要注册,还要审核,晕了Top
5 楼swelltan(阿谭)回复于 2005-01-31 11:33:17 得分 0
一般,只不过把大数据库分成了几个小的。Top
6 楼mymyal123(风之森)回复于 2005-01-31 11:38:49 得分 0
upTop
7 楼mymyal123(风之森)回复于 2005-01-31 11:42:34 得分 0
还要注册,太麻烦了
Top
8 楼cheng17(+天空+)回复于 2005-01-31 11:46:10 得分 0
还不错!Top
9 楼mackyliu(才子-54caizi.com)回复于 2005-01-31 11:46:54 得分 0
嘿嘿,来支持一下啰。。。Top
10 楼superdullwolf(超级大笨狼,每天要自强,MVP)回复于 2005-01-31 11:53:45 得分 20
下载烦琐。
说说你的思路?文件cache?Top
11 楼mackyliu(才子-54caizi.com)回复于 2005-01-31 11:58:24 得分 20
嘿嘿,我来帮贴代码。。。
sub works_list(pagesize,table,field,sqlwhere)
dim recordcount,pagecount,pageno
dim i
dim objfilesys,objdrives
set objfilesys=server.createobject("scripting.filesystemobject")
dim newfile
set newfile=objfilesys.opentextfile(server.mappath("cache/recordcount"&table&".ini"),1,true)
Do While Not newfile.AtEndOfStream
recordcount=newfile.readline
Loop
if recordcount="" or isempty(recordcount) then
sql="select count(id) from "&table&" "&sqlwhere
set rs=conn.execute(sql)
recordcount=rs(0)
set newfile=objfilesys.opentextfile(server.mappath("cache/recordcount"&table&".ini"),2,true)
newfile.writeline recordcount
end if
newfile.close
set newfile=nothing
set objfilesys=nothing
pagecount=((recordcount-1)\pagesize)+1'总页数
pageno=trim(request("pageno"))'当前页
if isempty(pageno) or not isnumeric(pageno) then
pageno=1
else
pageno=pageno
end if
if pageno<1 then
pageno=1
end if
if pageno*10 >= pagecount*10 then
pageno=pagecount
end if
if recordcount>0 then
call get_pageid(1000,pagesize,pageno,table,sqlwhere,pagecount)
end if
response.write "<table width='100%' border='1' style='font-size: 11pt; border-collapse: collapse'><tr height=30 ><td width=80>ID</td><td width=230>作品名称</td><td width=80>作者</td><td width=100>创作日期</td></tr>"
Sql="select top "&pagesize&" "&field&" from "&table&" "&sqlwhere
set rs=conn.execute(sql)
do while not rs.eof
i=i+1
response.write "<tr height=22><td >"&rs("id")&"</td><td><a href='HTTP://demo-asp.com'>"&rs("name")&"</a></td><td>"&rs("author")&"</td><td>"&rs("finishdate")&"</td></tr>"
rs.movenext
loop
response.write vbcrlf&"</table><form NAME='pagelist' method=get action='?'>"&_
vbcrlf&"<table width='100%' style='font-size: 11pt; border-collapse: collapse'><tr height=30><td><div align=center>"&_
vbcrlf&"页数<font color=#FF0000>"&pagecount&"</font>记录数<font color=#FF0000>"&recordcount&"</font> "&_
vbcrlf&"<a href='?pageno=1'>首页</a>|"&_
vbcrlf&"<a href='?pageno="&pageno-1&"'>上页</a>|"&_
vbcrlf&"<a href='?pageno="&pageno+1&"'>下页</a>|"&_
vbcrlf&"<a href='?pageno="&pagecount&"'>尾页</a> "&_
vbcrlf&"转到<input NAME='pageno' type=text size=6 maxlength='10' value="&pageno&" style='text-align: center'>页 "&_
vbcrlf&"<input type='submit' value='go'>"&_
vbcrlf&"</div></td></tr></form></table>"
end sub
sub get_pageid(k,pagesize,pageno,table,sqlwhere,pagecount)
dim pageid
redim pageid(k-1)
dim j'第几段
dim i
j=(pageno-1)\k
dim objfilesys,objdrives
set objfilesys=server.createobject("scripting.filesystemobject")
dim newfile
set newfile=objfilesys.opentextfile(server.mappath("cache/"&server.urlencode("pageid"&table&j&k&pagesize)&".ini"),1,true)
i=0
Do While Not newfile.AtEndOfStream
pageid(i)=newfile.readline
i=i+1
loop
if isempty(pageid) or pageid(0)="" then
set rs=server.createobject("adodb.recordset")
if j=0 then
rs.open "select top "&pagesize*k&" id from "&table&" ",conn,0,1
else
rs.open "select top "&pagesize*k&" id from "&table&" WHERE id >(select max(id) from (select top "&pagesize*k*j&" id from "&table&") as tb)",conn,0,1
end if
if not rs.eof then
set newfile=objfilesys.opentextfile(server.mappath("cache/"&server.urlencode("pageid"&table&j&k&pagesize)&".ini"),2,true)
for i=0 to k-1
if rs.eof then exit for
newfile.writeline rs(0)
pageid(i)=rs(0)
rs.move pagesize
next
end if
end if
newfile.close
set newfile=nothing
set objfilesys=nothing
if pageno mod k=0 or pageno=pagecount then
sqlwhere="WHERE id>="&pageid(pageno-j*k-1)
else
sqlwhere="WHERE id>="&pageid(pageno-j*k-1)&" and id<"&pageid(pageno-j*k)
end if
end sub
sub insert_datas(n)
dim i
for i=1 to n
conn.execute("insert into test(name, finishdate, author) SELECT top 10000 name,finishdate,author FROM test")
next
end subTop
12 楼onlytiancai(谁染枫林醉)回复于 2005-01-31 12:27:41 得分 0
看看Top
13 楼onlytiancai(谁染枫林醉)回复于 2005-01-31 12:34:56 得分 0
不想注册
Top
14 楼hackate(兰花开香入梦境,独思佳人亦飘然!!)回复于 2005-01-31 12:36:14 得分 0
顶呱呱!-_-!Top
15 楼ylben(杨威利)回复于 2005-01-31 12:41:48 得分 0
hoho,瞅瞅。Top
16 楼zxsjs(拐角)回复于 2005-01-31 13:28:57 得分 0
ding.................Top
17 楼cuiwl(龙城飞雨)回复于 2005-01-31 13:34:53 得分 0
http://www.joekoe.com/upload/forum/2005013110450689.rar
自己下载吧 ,176k 包括100000w记录的数据库 查看代码会发现有一自动天家属句的过程。天家到1000w吧
然后每隔1000页初始化一下 建议不要将其设置超过1000Top
18 楼clcy(风雨)回复于 2005-01-31 13:44:14 得分 0
不错
顶~~~~~~~~~~~~~~~~~~Top
19 楼cuiwl(龙城飞雨)回复于 2005-01-31 13:44:39 得分 0
希望前辈们能给个评语 很荣幸啊Top
20 楼rheleven(::☆痛并快乐着★::)回复于 2005-01-31 13:54:04 得分 0
UPTop
21 楼zzy0000(隐者)回复于 2005-01-31 13:56:44 得分 0
upTop
22 楼gu1dai(异域苍穹.百年飞行)回复于 2005-01-31 14:15:26 得分 0
呵呵Top
23 楼cuiwl(龙城飞雨)回复于 2005-01-31 15:30:55 得分 0
服武器及数据库的资源消耗在 初始化的 select count() 及一次性取得id 客护端 消耗为0 空间消耗为cache文件夹中的文件大小 100w 数据 cache的大小不会超过1m 适用于除论坛外的其它场合尤其是 新闻文章类 相比生成html文件的许多原程序,节省了大量的磁盘空间 保留了性能的同时,保留了数据的动态性 如点击次数等 网络流量仅为当叶显示数据 无其它js cookie之类影响
教其它分页最大的优势是: 消耗资源及少 翻页跳页速度恒定 不受记录数量及特定查询的影响(可以点击测试页面的分类及点击用户查看相关作品测试)
现在仍不满足的是 在搜索方面
sql的全文索引既占用数据库空间,数据量大时效率还是很低 对于 index service服务很不了解 一时也找不到好的学习资料
Top
24 楼cuiwl(龙城飞雨)回复于 2005-01-31 15:35:18 得分 0
排序好的数据表
取得每页第一个 id值 存入相应容器(app/ini),客户端的不考虑 执行一次数据库查询(采取分段方式提高速度)
select top ? * from tb where id>=pageid(pageno) and id<pageid(pageno+1)
自有服务器可采用 application
虚拟主机可采用 fso
Top
25 楼Shires(Trombone)回复于 2005-01-31 15:39:46 得分 0
ohTop
26 楼sysmaster(为什么我还不懂)回复于 2005-01-31 15:55:42 得分 0
感觉在数据库中分页(后显示)会更快Top
27 楼zwrtv(蝙蝠)回复于 2005-01-31 16:19:33 得分 0
支持下!!Top
28 楼colin310(秋风无痕&&GhostFox)回复于 2005-01-31 16:21:38 得分 0
upTop
29 楼syre(神仙)回复于 2005-01-31 16:39:48 得分 0
虚张声势。。。。。
Top
30 楼syre(神仙)回复于 2005-01-31 16:41:31 得分 0
很早就有在数据库中分页的办法了。。。。。。
楼主还是先去学习一下Top
31 楼dickcat(白羽轻翔)回复于 2005-01-31 16:52:53 得分 0
hehe~Top
32 楼cuipi2003(脆皮)回复于 2005-01-31 17:08:51 得分 0
这个只能适合连续不间断数据,当数据发生变化时候就要重新开始,这个显然是一个有漏洞的算法Top
33 楼kiccleaf(凯晰叶子(http://www.openzj.com))回复于 2005-01-31 17:17:15 得分 0
学习中……Top
34 楼wtiancai(博学,审问,慎思,明辨,笃行.)回复于 2005-01-31 17:35:56 得分 0
好东西Top
35 楼zsh211(经常在CSDN上看帖子数星星)回复于 2005-01-31 17:36:01 得分 0
kao.......Top
36 楼DARKNESSFALL(DARKNESSFALL)回复于 2005-01-31 17:36:48 得分 0
看看先!Top
37 楼cmslovehxh(关中刀客)回复于 2005-01-31 17:59:53 得分 0
到最后一页序号怎么还是1 2 3 4 5 6 7 8 9...........Top
38 楼zhk168(小康)回复于 2005-01-31 19:47:15 得分 0
可以..顶一下.Top
39 楼limx001(飞标)回复于 2005-01-31 20:20:40 得分 0
晕!注册了,还说有错误!!!!!Top
40 楼tanxin124(海色宇宙)回复于 2005-01-31 20:41:35 得分 0
什么意思,没看懂。。。Top
41 楼lubaixu(六百(lubai))回复于 2005-01-31 21:06:40 得分 0
看看吧。Top
42 楼AppleBBS(Dicky)回复于 2005-01-31 21:13:39 得分 0
不是很爽
Top
43 楼fengyun1314(追梦)回复于 2005-02-01 00:16:55 得分 0
是不是先取出一部分数据来,不用立即全部取出,这样速度就快了,是不是??Top
44 楼yaohai(【→☆烟客居☆↑】)回复于 2005-02-01 00:21:38 得分 0
pplaiTop
45 楼zorou_fatal(The world and system is even)回复于 2005-02-01 00:34:24 得分 30
可以拿xml做缓存的,而且是数据层缓存。
不过思路还可以。Top
46 楼zorou_fatal(The world and system is even)回复于 2005-02-01 00:39:57 得分 0
这种策略实际上适合于非即时读取数据库内容的站点,比如你提到的新闻。
但是如同论坛这样的可能就比较够戗,还是需要用数据库本身的存储过程加临时表来做。Top
47 楼zorou_fatal(The world and system is even)回复于 2005-02-01 00:41:46 得分 30
另外这种方式如果用户要调整浏览顺序,比如改变按照某个参数浏览的顺序,就不够灵活了。
建议你看看.net里的datagrid,会有一些启发。Top
48 楼cuiwl(龙城飞雨)回复于 2005-02-01 08:05:53 得分 0
相同服务器 500w记录的分页演示
我的分页演示:
http://www.demo-asp.com/demo/page_list.asp
特点:利用fso 动态存储记录总数 每页的pageid存为 总页数\1000+1个*.ini文件,无客户端缓存 无服务器端缓存
输出语句:select top n from tb where id>=pageid(i) and id<pigeid(i+1) 该语句部件所数据库,就像一张n条记录的表(当然稍慢一点) 网络流量也只有这部分 记录收尾无差异 不算fso 数据库查旬次数 3 且语句复杂效率一次性效率一般 综和效率极高 搜索效率较低 适用范围 新闻文章类
交互功能:在于fso
叶子的分页演示:
http://www.demo-asp.com/demo/pageac.asp
特点:利用cookie 存储记录总数 js输出翻页代码
输出语句:Showo_Rs.AbsolutePosition=(Showo_CurrPage-1)*Showo_PageSize+1 快速的查询相邻记录,很快,记录首尾速度有差异,等价于pagesize + absolutpage(不算cookie)数据库查旬次数 3(包括AbsolutePosition) 一次性效率极高 搜索效率较高 适用范围 新闻文章类
交互功能:在于cookie
才子的签名:http://www.54caizi.com/pageac/
另外有 无限流 www.imagecity.org
没找到access版本,500w sql 时间40ms左右
总结完毕Top
49 楼cuiwl(龙城飞雨)回复于 2005-02-01 08:09:10 得分 0
代码总是可以优化
xml还不太懂 存储过程也只是会写
我想 0101010101010101 0101010101010111100010010 1000011000100
这样的代码 家长最好的 方法 才是最牛的
可惜不是人干的活啊Top
50 楼cuiwl(龙城飞雨)回复于 2005-02-03 09:49:52 得分 0
<%@language="vbscript" codepage="936"%>
<%
option explicit
response.buffer=true
server.scripttimeout=99999
dim loadtime,strtime,endtime
strtime=timer
'*****************************************************************
'原创作者: cuiwl(QQ:27086712)
'电子邮件: longchengfy@hotmail.com
'个人主页: www.demo-asp.com
'*****************************************************************
'on error resume next
dim conn,connstr,sql,rs
set conn=server.createobject("adodb.connection")
'connstr="driver={microsoft access driver (*.mdb)};dbq="&server.mappath("test.mdb")
connstr="provider=microsoft.jet.oledb.4.0;Data Source="&server.mappath("test.mdb")
conn.open connstr
'if err.number<>0 then
'response.write "站点维护中……"
'response.end
'end if
%>
<HTML>
<HEAD>
<title>CUIWL的分页代码测试--( www.demo-asp.com ASP作品演示网)</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
</HEAD>
<BODY>
<center>
<table width="700" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<%
dim sqlwhere
sqlwhere=""
call works_list(25,10000,"test","id,name,finishdate,author",sqlwhere,"order by id desc")
%>
</td>
</tr>
</table>
<table border="0" width="700" cellpadding="0" height="30" style="font-size: 9pt; border-collapse: collapse">
<tr>
<td align="center">CUIWL的分页代码测试 执行时间:
<%
endtime=timer
loadtime=(endtime-strtime)*1000
response.write loadtime
%>
毫秒
</td>
</tr>
</table>
</BODY>
</HTML>
<%
'call insert_datas(1) '生成测试数据
conn.close
set conn=nothing
'============================================SUB===========================================
sub works_list(pagesize,k,table,field,sqlwhere,order_by)
'参数说明:pagesize 每页记录数;k 按记录数分段,每段记录数;table 表名称;field 字段名称;sqlwhere 筛选条件;order_by 排序方式
dim recordcount,pagecount,pageno
dim i
dim objfilesys,objdrives
dim newfile
set objfilesys=server.createobject("scripting.filesystemobject")
set newfile=objfilesys.opentextfile(server.mappath("cache/recordcount"&table&".ini"),1,true)
Do While Not newfile.AtEndOfStream
recordcount=newfile.readline
Loop
if recordcount="" or isempty(recordcount) then
sql="select count(id) from "&table&" "&sqlwhere
set rs=conn.execute(sql)
recordcount=rs(0)
set newfile=objfilesys.opentextfile(server.mappath("cache/recordcount"&table&".ini"),2,true)
newfile.writeline recordcount
end if
newfile.close
set newfile=nothing
set objfilesys=nothing
pagecount=((recordcount-1)\pagesize)+1'总页数
pageno=trim(request("pageno"))'当前页
if isempty(pageno) or not isnumeric(pageno) then
pageno=1
else
pageno=pageno
end if
if pageno<1 then
pageno=1
end if
if pageno*10 >= pagecount*10 then
pageno=pagecount
end if
dim j'得出共有几段
j=(recordcount-1)\k+1
dim topid
redim topid(j)
'--------------------------------------------------------------------------------------------
set objfilesys=server.createobject("scripting.filesystemobject")
set newfile=objfilesys.opentextfile(server.mappath("cache/topid"&table&".ini"),1,true)
i=0
Do While Not newfile.AtEndOfStream
topid(i)=newfile.readline
i=i+1
Loop
if isempty(topid) or topid(0)="" then
set rs=conn.execute("select id from "&table&" "&sqlwhere&" "&order_by)
set newfile=objfilesys.opentextfile(server.mappath("cache/topid"&table&".ini"),2,true)
for i=0 to j-1
topid(i)=rs(0)
newfile.writeline topid(i)
if i<j-1 then
rs.move k
else
rs.move recordcount-k*(j-1)
end if
next
end if
newfile.close
set newfile=nothing
set objfilesys=nothing
'--------------------------------------------------------------------------------------------
if recordcount>0 then
'--------------------------------------------------------------------------------------------
dim pageid
dim n'每段页数
n=k\pagesize
dim l'第几段
l=(pageno-1)\n
redim pageid(n)
set objfilesys=server.createobject("scripting.filesystemobject")
set newfile=objfilesys.opentextfile(server.mappath("cache/"&server.urlencode("pageid"&table&l)&".ini"),1,true)
i=0
Do While Not newfile.AtEndOfStream
pageid(i)=newfile.readline
i=i+1
loop
if isempty(pageid) or pageid(0)="" then
set rs=server.createobject("adodb.recordset")
if j<>1 and l<>j-1 then
sqlwhere="where id<="&topid(l)&" and id>"&topid(l+1)
end if
if j=1 or l=j-1 then
sqlwhere="where id<="&topid(l)
end if
set rs=conn.execute("select top "&k&" id from "&table&" "&sqlwhere&" "&order_by)
if not rs.eof then
set newfile=objfilesys.opentextfile(server.mappath("cache/"&server.urlencode("pageid"&table&l)&".ini"),2,true)
rs.move pagesize-1
for i=0 to n-1
if rs.eof then exit for
pageid(i)=rs(0)
newfile.writeline pageid(i)
rs.move pagesize
next
end if
end if
newfile.close
set newfile=nothing
set objfilesys=nothing
if pagecount<=1 then
sqlwhere=""
else
select case pageno
case pagecount
sqlwhere="WHERE id<"&pageid(pageno-l*n-2)
case else
if pageno mod n=1 then
sqlwhere="WHERE id>="&pageid(pageno-l*n-1)&" and id<="&topid(l)
else
sqlwhere="WHERE id>="&pageid(pageno-l*n-1)&" and id<"&pageid(pageno-l*n-2)
end if
end select
end if
'--------------------------------------------------------------------------------------------
end if
response.write "<table width='100%' style='font-size: 9pt; border-collapse: collapse'><tr height=30 ><td width=80>序号</td><td width=230>作品名称</td><td width=80>作者</td><td width=100>创作日期</td></tr>"
i=PAGENO*pagesize-1
Sql="select top "&pagesize&" "&field&" from "&table&" "&sqlwhere&" "&order_by
set rs=conn.execute(sql)
do while not rs.eof
i=i+1
response.write "<tr height=22><td >"&rs("id")&"</td><td>"&rs("name")&"</td><td>"&rs("author")&"</td><td>"&rs("finishdate")&"</td></tr>"
rs.movenext
loop
response.write vbcrlf&"</table><form NAME='pagelist' method=get action='?'>"&_
vbcrlf&"<table width='100%' style='font-size: 9pt; border-collapse: collapse'><tr height=30><td><div align=center>"&_
vbcrlf&"页数<font color=#FF0000>"&pagecount&"</font>记录数<font color=#FF0000>"&recordcount&"</font> "&_
vbcrlf&"<a href='?pageno=1'>首页</a> | "&_
vbcrlf&"<a href='?pageno="&pageno-500&"'>上400页</a> | "&_
vbcrlf&"<a href='?pageno="&pageno-1&"'>上页</a> | "&_
vbcrlf&"<a href='?pageno="&pageno+1&"'>下页</a> | "&_
vbcrlf&"<a href='?pageno="&pageno+500&"'>下400页</a> | "&_
vbcrlf&"<a href='?pageno="&pagecount&"'>尾页</a> "&_
vbcrlf&"转到<input NAME='pageno' type=text size=6 maxlength='10' value="&pageno&" style='text-align: center'>页 "&_
vbcrlf&"<input type='submit' value='go'>"&_
vbcrlf&"</div></td></tr></form></table>"
end sub
sub insert_datas(n)
dim i
for i=1 to n
conn.execute("insert into test(name, finishdate, author) SELECT top 10000 name,finishdate,author FROM test")
next
end sub
%>
性能提高了很多Top
51 楼zhlym(ming)回复于 2005-06-04 15:37:11 得分 0
记录一下,可后用得到Top




