怎样提高分页速度,全分相送!!!

adf3wswwe3 2004-12-22 01:56:47
<!-- #include file="../Inc/conn.asp" -->
<%
dim i,intPage,page,pre,last,filepath
set rs = server.CreateObject("adodb.recordset")
sql="select * from user order by user_ID desc"
rs.PageSize = 20 '这里设定每页显示的记录数
rs.CursorLocation = 3
rs.Open sql,conn,0,2,1 '这里执行你查询SQL并获得结果记录集
pre = true
last = true
page = trim(Request.QueryString("page"))

if len(page) = 0 then
intpage = 1
pre = false
else
if cint(page) =< 1 then
intpage = 1
pre = false
else
if cint(page) >= rs.PageCount then
intpage = rs.PageCount
last = false
else
intpage = cint(page)
end if
end if
end if
if not rs.eof then
rs.AbsolutePage = intpage
end if
%>
循环体开始:
<%
for i=1 to rs.PageSize
if rs.EOF or rs.BOF then exit for
%>
..................
..................
...................
<%
rs.movenext
next
%>
循环体结束
分页部分:
<table width="99%" border="1" cellpadding="2" cellspacing="2" borderColorLight=#808080 borderColorDark=#ffffff>
<tr>
<%if rs.pagecount > 0 then%>
<td width="13%" align="left">当前页<%=intpage%>/<%=rs.PageCount%></td>
<%else%>
<td width="41%" align="left">当前页0/0</td><%end if%>
<td width="46%" align="right"> <a href="document_manage.asp?page=1">首页</a>|
<%if pre then%>
<a href="document_manage.asp?page=<%=intpage -1%>">上页</a>| <%end if%>
<%if last then%>
<a href="document_manage.asp?page=<%=intpage +1%>">下页</a> |<%end if%>
<a href="document_manage.asp?page=<%=rs.PageCount%>">尾页</a>|转到第
<select name="sel_page" onchange="javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to rs.PageCount
if i = intpage then%>
<option value="document_manage.asp?page=<%=i%>" selected><%=i%></option>
<%else%>
<option value="document_manage.asp?page=<%=i%>"><%=i%></option>
<%
end if
next
%>
</select>页</font>
</td>
</tr>
</table>
--------------------------------------
用这样的分页处理之后,如果数据库中有5000条记录,它的执行速度很明显的变慢,


能不能对它进行改编呢?以加快分页速度???
...全文
103 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kof_alay 2004-12-23
  • 打赏
  • 举报
回复
Set rstData = Server.CreateObject("ADODB.RecordSet")

写错了,,是,,
Set rs = Server.CreateObject("ADODB.RecordSet")
kof_alay 2004-12-22
  • 打赏
  • 举报
回复
函数页function.asp
<%
Function rsToPageHtml(rsPage,PageSize,rsUrl)
If rsPage.EOF Then
rsToPageHtml = "没有记录!"
Exit Function
End If
Dim rsCount,PageCount,Page,sScriptName,strTemp
Dim tmpPage, intPage, allPage
rsCount = rsPage.RecordCount
rsPage.PageSize = PageSize
PageCount = rsPage.PageCount
Page = Request("Page")
Page = Clng(Page)
if Page < 1 then Page = 1
If Page > Pagecount Then Page = Pagecount
rsPage.AbsolutePage = Page
'sScriptName = Request.ServerVariables("SCRIPT_NAME")
if InstrRev(rsUrl,".asp?") > 0 then
rsUrl = rsUrl & "&Page="
else
rsUrl = rsUrl & "?Page="
end if
strTemp = ""
tmpPage = 10
intPage = Int((Page-1) / tmpPage)
allPage = Int(Pagecount / tmpPage)
If Page<>1 and intPage<>0 Then strTemp = strTemp &"<a href="""& rsUrl &"1"" title=首页><font face=webdings>9</font></a> "
If intPage>0 Then strTemp = strTemp &"<a href="""& rsUrl & ((intPage-1)*tmpPage+1) &""" title=前十页><font face=webdings>7</font></a> "
If intPage<allPage Then
For n=(intPage*tmpPage+1) To (intPage+1)*tmpPage
If n=Page Then
strTemp = strTemp &" <font color=red><b>"& n &"</b></font> "
Else
strTemp = strTemp &" <a href="""& rsUrl & n &"""><b>"& n &"</b></a> "
End If
Next
Else
For n=(intPage*tmpPage+1) To Pagecount
If n=Page Then
strTemp = strTemp &" <font color=red><b>"& n &"</b></font> "
Else
strTemp = strTemp &" <a href="""& rsUrl & n &"""><b>"& n &"</b></a> "
End If
Next
End If

If intPage<allPage Then strTemp = strTemp &"<a href="""& rsUrl & ((intPage+1)*tmpPage+1) &""" title=后十页><font face=webdings>8</font></a> "
If Page<>Pagecount and intPage<>allPage Then strTemp = strTemp &"<a href="""& rsUrl & Pagecount &""" title=末页><font face=webdings>:</font></a> "
strTemp = strTemp &"  共"& PageCount &"页 "&"共 "&rsCount&" 条记录"
rsToPageHtml = strTemp
End Function
%>

客户端页:
<!--include file=conn.asp-->
<!--include file=function.asp-->

<% const PageSize = 20
rsUrl = "default.asp"
Set rstData = Server.CreateObject("ADODB.RecordSet")
rs.open "select * from new",conn,1,1
strPages = rsToPageHtml(rs,PageSize,rsUrl)
For iCount=1 To PageSize
If rs.EOF Then Exit For
%>

<table width="99%" height="68" border="0" align="center" cellspacing="0">
<tr align="center">
<th height="25" ><%=rs("id")%></th>
<th ><%=rs("title")%></th>
<th ><%=rs("time")%></th>
<th ><%=rs("kind")%></th>
<th ><%=rs("words")%></th>
</tr>
</table>
<table width="99%" height="68" border="0" align="center" cellspacing="0">
<tr>
<td height="22" colspan="7" class="th" > <%=strPages%></td>
</tr>
</table>
<%
rs.movenext
next
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
adf3wswwe3 2004-12-22
  • 打赏
  • 举报
回复
f
adf3wswwe3 2004-12-22
  • 打赏
  • 举报
回复
请指点??
madpolice 2004-12-22
  • 打赏
  • 举报
回复
把代码中下面的语句都去掉就快了:
rs.PageCount
rs.PageSize
rs.AbsolutePage
rs.eof

怎么去掉,你自己动动脑筋.

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧