分页程序有点小问题

oomen 2006-11-25 02:07:09
平时基本上都用这个分页
<%
const maxperpage=20'每页的记录数
dim currentpage
objRS.pagesize=maxperpage
currentpage=request.querystring("pageid")
if currentpage="" then
currentpage=1
elseif currentpage<1 then
currentpage=1
else
currentpage=clng(currentpage)
if currentpage > objRS.pagecount then
currentpage=objRS.pagecount
end if
end if

if not isnumeric(currentpage) then
currentpage=1
end if
dim totalput,n
totalput=objRS.recordcount
if totalput mod maxperpage=0 then
n=totalput\maxperpage
else
n=totalput\maxperpage+1
end if
if n=0 then
n=1
end if
objRS.move(currentpage-1)*maxperpage
i=0
do while i< maxperpage and not objRS.eof







Response.Write " <li> <A HREF='02.asp?id=" & objRS("id") & "'target='_blank'>" & left(objRS("tittle"),30) & " </A>"

Response.Write "("& objRS("time") &")<br></li>"




i=i+1
objRS.MoveNext
Loop
%>
<br><br>


页数:<%=currentpage%>/<% =n%>
<%k=currentpage
if k<>1 then%>
<a href="main08.asp?pageid=1">首页</a>
<a href="main08.asp?pageid=<%=k-1%>">上一页</a><font color="#FFFFFF">
<%else%>
首页 上一页
<%end if%>
<%if k<>n then%>
<a href="main08.asp?pageid=<%=k+1%>">下一页</a>
<a href="main08.asp?pageid=<%=n%>">尾页</a><font color="#FFFFFF">
<%else%>
下一页 尾页
<%end if%>
<span class="STYLE1">总纪录<span class="STYLE1"><%=totalput%>条</span></span></div>
<%
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>


其他没有一点问题,但是当记录数为0时,就会出错,当记录数大于0时,一点问题也没有。
...全文
198 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tangqiaojie 2006-11-25
  • 打赏
  • 举报
回复
objRS.move(currentpage-1)*maxperpage
这句吧
oomen 2006-11-25
  • 打赏
  • 举报
回复
......
51one 2006-11-25
  • 打赏
  • 举报
回复
给个例子,比比看


MaxPerPage=10
%>
<form method="POST" action="?action=showuser">
<BR><table cellpadding=3 cellspacing=1 align=center class=tableborder1>
<TR><Th colSpan=3 align=left height=25>  <a href="?action=main">介绍</a> | <a href="?action=showuser">名单</a></Th></TR>
<TR>
<td width=10% align=center class=tablebody1>用户ID</td>
<td width=15% align=center class=tablebody1>用户名</td>
<td width=75% align=center class=tablebody1>例子</td>
</TR>
<TR>
<td width=100% align=center class=tablebody1 colSpan=3 height=15></td>
</TR>
<%

set rs=server.createobject("adodb.recordset")
sql="select username,xzdata,userid from [user] where xzdata<>'' order by userid ASC"
rs.Open sql,conn,1,3
if rs.eof or rs.bof then
%>
<TR height=40><td colSpan=3 align=center class=tablebody1 width=100%>暂时还没有会员获得勋章</td></tr>
<%
else
'################分页处理

rs.pagesize=MaxPerPage '得到每页数
mpage=rs.pagecount '得到总页数
allshu=rs.recordcount
if request("page")<>"" then
if cint(request("page"))<1 or cint(request("page"))>mpage then
currentPage=1
else
currentPage=cint(request("page"))
end if
else
currentPage=1
end if
rs.move (currentPage-1)*MaxPerPage

'################分页处理结束
Do While not rs.eof
for b=0 to ubound(split(rs(1),"|||"))
if split(rs(1),"|||")(b)<>"0" then
set rsa=conn.execute("select xzname,xzpicurl from xzdata where xzid="&split(rs(1),"|||")(b)&"")
xzpic=xzpic&"  <img src=pic/"&rsa(1)&" border=0 alt="&rsa(0)&">"
end if
next
%>

<TR height=40>
<td width=10% align=center class=tablebody1><%=rs(2)%></td>
<td width=15% align=center class=tablebody1><a href=dispuser.asp?id=<%=rs(2)%> target=_black><%=rs(0)%></a></td>
<td width=75% align=center class=tablebody1><%=xzpic%></td>
</TR>
<%

xzpic=""
rsa.close
set rsa=nothing

i=i+1
rs.movenext
if i>= MaxPerPage then exit do
Loop
'#######显示分页
if allshu>0 then
%>
<TR height=40><td colSpan=3 align=center class=tablebody1 width="100%">  找到:<b><%=allshu%></b>个 页次<b><%=currentPage%></b>/<b><%=mpage%></b> 每页<b><%=MaxPerPage%></b>  
<%
pageno=currentPage
if cint(pageno)>1 then
%>
<a href="?action=showuser" title="最前页"><%end if%><font face="Webdings">9</font></a> <%if cint(pageno)>1 then%><a href="?action=showuser&page=<%=pageno-1%>" title="上一页"><%end if%><font face="Webdings">7</font></a>
<%
pp=cint(pageno)-5
if pp<1 then
pp=1
end if
for pno=pp to mpage
if len(pno)=1 then
end if
p=p+1
if pno*1=cint(pageno)*1 then
%>

 <font color="#FF0000">[<%=pno%>]</font><%else%> <a href="?action=showuser&page=<%=pno%>">[<%=pno%>]</a><%end if%><%
if p>=11 then exit for
next%> <%if cint(pageno)< mpage then%><a href="?action=showuser&page=<%=pageno+1%>" title="下一页"><%end if%><font face="Webdings">8</font></a> <%if cint(pageno)< mpage then%><a href="?action=showuser&page=<%=mpage%>" title="最后页"><%end if%><font face="Webdings">:</font></a>  到<input name="page" size="3">页<input type=submit name=submit value=转到>

<%
end if
end if
rs.close
set rs=nothing
%>

</td></tr></table></form>
<%
end sub
%>
myvicy 2006-11-25
  • 打赏
  • 举报
回复
你判断一下,objRS.eof的时候不调用相关rs的属性来处理变量
例如
if not objRS.eof then
if currentpage > objRS.pagecount then
currentpage=objRS.pagecount
end if
end if

28,390

社区成员

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

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