| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2742 人关注过本帖
标题:[求助]为什么说叶子的asp分页类高效?
只看楼主 加入收藏
chain710
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2006-2-5
收藏
 问题点数:0 回复次数:11 
[求助]为什么说叶子的asp分页类高效?
为什么说叶子的asp分页类高效?
看了代码,感觉还是要预读所有的记录阿

Case Else '其他情况按最原始的方法处理(AC同理)
Set Rs = Server.CreateObject ("Adodb.RecordSet")
ResultSet_Sql="SELECT "&sField&" FROM "&sTable&" "&sCondition&" "&sOrderBy
Rs.Open ResultSet_Sql,oConn,1,1,&H0001
Rs.AbsolutePosition=(iPageCurr-1)*iPageSize+1

后来自己用原始的方法分页,1000000条记录,发现速度没什么区别,为什么阿?

诚心求教!先谢谢各位高手了
搜索更多相关主题的帖子: 叶子 asp 
2006-02-05 16:28
盖茨他爹
Rank: 6Rank: 6
等 级:贵宾
威 望:28
帖 子:5255
专家分:0
注 册:2005-5-3
收藏
得分:0 
没研究过,俺都用最原始的。
2006-02-05 16:37
chain710
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2006-2-5
收藏
得分:0 

难道网上的那些快速分页都是糊弄人的?:(

2006-02-05 16:40
盖茨他爹
Rank: 6Rank: 6
等 级:贵宾
威 望:28
帖 子:5255
专家分:0
注 册:2005-5-3
收藏
得分:0 
不是糊弄人的,只不过用起来麻烦,默认的用起来简单,看你开发什么了,如果开发一个大型的论坛或新闻网站,记录有几十万条,当然要考虑优化,就要用一些快速的分页方法,如果十开发一个企业宣传网站,或类似OA的管理系统,本身信息量不会多大,用快速分页就是多此一举了
2006-02-05 16:54
chain710
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2006-2-5
收藏
得分:0 

可是我用原始的分页方法测试1000000条记录,速度没有明显差异阿~

请问这是为什么?谢谢!

2006-02-05 17:01
盖茨他爹
Rank: 6Rank: 6
等 级:贵宾
威 望:28
帖 子:5255
专家分:0
注 册:2005-5-3
收藏
得分:0 
不清楚
2006-02-05 17:04
chain710
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2006-2-5
收藏
得分:0 

PS:叶子的asp分页类好像也不是如我想象中只读取需要的记录

他的方法也是预读所有记录,设置absoluteposition,再用getrows方法得到指定数目的记录

而且大多快速分页思想都是第一次读取所有记录,并做标记,以后读取利用标记来分离纪录

如果是一个频繁更新的数据库,那该如何快速分页呢?

2006-02-05 17:06
chain710
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2006-2-5
收藏
得分:0 
自己顶起!
2006-02-05 18:11
rainic
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:2367
专家分:0
注 册:2005-8-9
收藏
得分:0 
如果一开始不是把全部的记录读出,哪会知道有多少页?就更不用说分页了

2006-02-05 21:48
withtao
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-10-25
收藏
得分:0 
我写的分页类
1 只取需要得数据 sql最优化
2 可以排序
3 速度最快
4 史上最好 呵呵
5 用用就知道了!

<!--#include file="conn.asp"-->

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<%

'/////////////////转载请注明---本类由withtao 维护////////////////////////
'/////////////////超强的asp分页类/////////////////////////////////////////////////////////////////////
Call ceshi

Sub ceshi()
dim p
set p = New divp
p.item = Array("did","mp","ddate","txt","flag","part")
p.item2 = Array("","","","","","")
p.sql = " from mrecord,perday where perday.phone=mrecord.mp"

p.item1 = Array("did","手机号","定制时间","类型","状态","时间段")
p.url=" "
p.MaxPerPage = 20
p.init

set p = nothing



'p.sql = "SELECT COUNT(dstate) AS num, dstate FROM muser GROUP BY dstate"
'p.item = Array("dstate","num")
'p.item = Array("id","rnd")
'p.item1 = Array("ID","保护码")
'p.sql = "SELECT * FROM rnd"
End sub










'////////////////////////////////////////////////////////////
Class divp
dim item,item1,item2
dim url
dim px,desc

dim totalPut 'all records
dim CurrentPage 'current page NO.
dim TotalPages 'total pages
dim i,j
dim sql,sql1
dim rs,rs1
dim rstype
dim typesql
dim MaxPerPage
dim pp

Sub initsql()
px = request.Form("px")
desc = cint(request.Form("desc"))
px = replace(px,"'","")

pp = request.Form("page")

if not isempty(pp) then 'the value when click next page input
currentPage = clng(request.Form("page"))
if currentPage = 0 then
currentPage = clng(request.Form("page")) '设置当前页码
end if
else
currentPage = 1
end if
sql1 = "select count(*) as num" & sql
sql = "select top " & currentPage * MaxPerPage & " * " & sql

if px = "" then px = item(0)
sql = sql & " order by " & px
url = "?px=" & px
'response.Write "-------" & desc & "------------"

if isempty(item1) then item1 = item

if desc = 1 then '/////////fanxu反序///////////////////////////////////////////////////////
sql = sql & " DESC"
sql = "select * from (select top " & MaxPerPage &" * from (" & sql & ") tb1 order by " & px & " ) tb2 order by " & px & " desc"

'url = "?px=" & px & "&desc=1"

else'//////////////正序///////////////////////////////////////////////////////////////////////
sql = "select * from (select top " & MaxPerPage &" * from (" & sql & ") tb1 order by " & px & " desc ) tb2 order by " & px

end if

end sub

'Sub Class_Initialize()
Sub init()

call initsql()
'const MaxPerPage = 20 'NO.of record per page
'//////////////////////////////////////////////////////////////////////////////

response.Write "<------" & sql & "---------->"
Set rs = Server.CreateObject("ADODB.Recordset")
on error resume next
rs.open sql,conn,1,1


if err.num > 0 then
px = item(0)
err.clear
rs.open sql,conn,1,1

end if
'//////////////////////////////////////////////////////////////////////////
rs1 = conn.execute(sql1)

'response.Write rs1("num") & "--------------"
'//////////////////////////////////////////////////////////////////////////
if rs.eof and rs.bof then
response.write "<p align='center'> 还没有任何东西</p>"
else
totalPut = rs1("num")
'totalPut=rs.recordcount
'**********************
if currentpage < 1 then
currentpage = 1
end if
'/////////////////////////////////////////////////////
if (currentpage - 1) * MaxPerPage > totalput then '即最后一页不满
if (totalPut mod MaxPerPage) = 0 then '正好除尽的情况
currentpage = totalPut \ MaxPerPage
else
currentpage = totalPut \ MaxPerPage + 1
end if
end if
'/////////////////////////////////////////////////
if currentPage = 1 then
showContent
showpage totalput,MaxPerPage',url
else
if (currentPage - 1)*MaxPerPage < totalPut then
'rs.move (currentPage-1) * MaxPerPage
'dim bookmark
'bookmark = rs.bookmark
showContent
showpage totalput,MaxPerPage',url
else
currentPage = 1
showContent
showpage totalput,MaxPerPage',url
end if
end if
'////////////////////////////////////////////////////////////////////
end if

End sub

Sub Class_terminate()
'//////////////////////////////////////////////////////////////////////////
'rs.close
set rs = nothing
'conn.close
set conn = nothing
End sub



'////////////////////循环次数由 每页最多条 控制//////////////////////////
Sub showContent()
dim i
i = 0
%>

<style type="text/css">
<!--
body{
font-size: 13px;
line-height: 16px;
}
.s1 {
font-size: 13px;
line-height: 16px;
}
#AutoNumber1 a:link {
color: #FFFFFF;
}
#AutoNumber1 a {
text-decoration: none;
}
#AutoNumber1 a:visited {
color: #FFFFFF;
}
-->
</style>
<table border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC" class="s1" id="AutoNumber1" style="border-collapse: collapse" >
<tr bgcolor="#0066CC">
<% for p = 0 to ubound(item1) %>
<td align="center" >
<font color="#FFFFFF">
<a href="#" onclick="js:sethide1('px','<%= item2(p) %><%= item(p) %>');sethide('desc','0');">↓</a>
<%= item1(p) %>
<a href="#" onclick="js:sethide1('px','<%= item2(p) %><%= item(p) %>');sethide('desc','1');">↑</a>
</font></td>
<% next %>
<!-- <td ><font color="#FFFFFF">删除</font></td> -->
</tr>
<% do while not rs.eof %>
<tr bgcolor="eeeeee">
<% for p = 0 to ubound(item) %>
<td align="center"><%= rs(item(p))%> </td>
<% next %>
<!-- <td align="center"><a href="del.asp?did=<%= rs(item(0))%>" onclick="return confirm('想好了?删不?');">删除</a> </td> -->
</tr>
<%
i = i + 1
if i >= MaxPerPage then exit do
rs.movenext
loop
%>
</table>
<% End sub




'显示页码,和翻页的函数
'Function showpage(totalnumber,maxperpage,filename)
Function showpage(totalnumber,maxperpage)
dim n 'n是总页面数 计算出来 用取整的方法
if totalnumber mod maxperpage = 0 then
n = totalnumber \ maxperpage
else
n = totalnumber \ maxperpage+1
end if
%>
<!-- 提交的是页码 -->
<div align='center'>
<form action="" method="post" name="from2" id="from2">

<%
px = request.Form("px")

if CurrentPage < 2 then '首页
response.write "<font color='#000080'>首页 上一页</font> "
else
%>
<a href='#' onclick="js:sethide('page','1');">首页</a>
<a href='#' onclick="js:sethide('page','<%= CurrentPage - 1 %> ');">上一页</a>
<%end if

if n - currentpage < 1 then '尾页
response.write "<font color='#000080'>下一页 尾页</font>"
else
%>
<a href='#' onclick="js:sethide('page','<%= ( CurrentPage + 1 ) %>');">下一页</a>
<a href='#' onclick="js:sethide('page','<%= n %>');">尾页</a>
<% end if
%>
<font color='#000080'> 页次:</font><strong><font color='red'><%= CurrentPage %></font></strong><font color='#000080'><strong>/<%= n %></strong>页</font>
<font color='#000080'> 共<b><%= totalnumber %></b>条record <b><%= maxperpage %></b>条record/页</font>
<font color='#000080'>转到:</font>

<input type='text' name='page' size='6' maxlength='10' class='smallInput' value='<%= currentpage %>'>
<input name='queding' type="submit" id="queding" value="确定" >
<input name="px" type="hidden" id="px" value="<%= px %>" />
<input name="desc" type="hidden" id="desc" value="<%= desc %>" />
</form>
</div>
<script language="JavaScript" type="text/javascript">
function sethide1(id,vl){
eval('document.from2.'+id+'.value="'+vl+'"');
//from2.submit();
}

function sethide(id,vl){
eval('document.from2.'+id+'.value="'+vl+'"');
//var p = confirm(" sure ?");
//alert(p);
//if (p)
//{
from2.submit()};
//}
</script>

<%

End function

End class
%>


2006-10-25 15:55
快速回复:[求助]为什么说叶子的asp分页类高效?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017721 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved