分页问题,其他页显示良好,无论最后一页还有几条都只能显示一条

feipeng 2003-08-24 01:41:29
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>分页</title>
</head>
<body>
<!-- #include file="connect.asp" -->
<%
'接受外部值
currentpage=request("currentpage")
dim exec
dim i
exec="select id from dcrczp order by id desc"
set rs=conn.execute(exec)
'设置每页的记录数
rs.pagesize=25
'总记录数
rs.movefirst
do while not rs.eof
tempcount=tempcount+1
rs.movenext
loop
rs.movefirst
'总页数
pagenum=tempcount\rs.pagesize+1
'处理当前页
currentpage=request.querystring("currentpage")
if currentpage="" then
currentpage=1
end if

'记录从某页开始到该页结束显示
if cint(currentpage)=cint(pagenum) then
houmanyfields=(tempcount mod rs.pagesize)-1
else
howmanyfields=24
end if
rs.move (currentpage-1)*25
for i=0 to howmanyfields
%>
<table>
<tr>
<td><% =rs("id")%></td>
</tr>
<%
rs.movenext
next
%>
<tr>
<td>共<%=tempcount%>条记录,<%=pagenum%>页,当前第<%=currentpage%>页</td>
<td>
<%
'设置首页,上一页,下一页,尾页的连接
if currentpage<>1 then
response.write ("[<a href='dcrc_zp1.asp?currentpage=1' >首页</a>]")
response.write ("[<a href='dcrc_zp1.asp?currentpage="¤tpage-1&"'>上一页</a>]")
else
response.write("[首页][上一页]")
end if
if (currentpage+1)<>(pagenum+1) then
response.write ("[<a href='dcrc_zp1.asp?currentpage="¤tpage+1&"' >下一页</a>]")
response.write ("[<a href='dcrc_zp1.asp?currentpage="&pagenum&"'>尾页</a>]")
else
response.write("[下一页][尾页]")
end if
%>
</td>
</tr>
</table>

</body>
</html>
...全文
74 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
feipeng 2003-08-24
  • 打赏
  • 举报
回复
已经解决了,谢谢
feipeng 2003-08-24
  • 打赏
  • 举报
回复
511214(小少) :
pagenum=INT(RS.recordcount /rs.pagesize* (-1))*(-1)
运行可以出来,但最后有
“ADODB.Field 错误 '80020009'
BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。”
的错误
mudsong 2003-08-24
  • 打赏
  • 举报
回复
果然,我在自己机子上试了,按你的代码,果然到最后一页就只显示一个记录

你只要把
'总页数
pagenum=tempcount\rs.pagesize+1

改为
pagenum=tempcount/rs.pagesize
pagenum=int(pagenum)
if (tempcount mod rs.pagesize)>0 then
pagenum=pagenum +1
end if

应该可以了
511214 2003-08-24
  • 打赏
  • 举报
回复
你先把pagenum改成pagenum=INT(RS.recordcount /pagesize* -1)*-1看看还有什么问题
mudsong 2003-08-24
  • 打赏
  • 举报
回复
总页数设置有问题
pagenum=tempcount\rs.pagesize+1
如果你总记录恰好是25的倍数,那你不就多算出一页来了吗?
应该这样
pagenum=tempcount/rs.pagesize
pagenum=int(pagenum)
if (tempcount mod rs.pagesize)>0 then
pagenum=pagenum +1
end if
511214 2003-08-24
  • 打赏
  • 举报
回复
'总记录数
rs.movefirst
do while not rs.eof
tempcount=tempcount+1
rs.movenext
loop
rs.movefirst
'总页数
pagenum=tempcount\rs.pagesize+1
总的记录数用:rs.recordcount即可不必那么麻烦
计算总页数时应该这样:pagenum=INT(RS.recordcount /pagesize* -1)*-1
假如总页数是50,那么你的结果是3,显然是错的
feipeng 2003-08-24
  • 打赏
  • 举报
回复
clng()是干什么用的?
最后一页还是只有一条
linday 2003-08-24
  • 打赏
  • 举报
回复
urrentpage=clng(request("currentpage"))
feipeng 2003-08-24
  • 打赏
  • 举报
回复
能不能分析一下我的代码,到底错在哪里?
511214 2003-08-24
  • 打赏
  • 举报
回复
不行的话,再看看这里
http://expert.csdn.net/Expert/topic/2086/2086064.xml?temp=.1258661
feipeng 2003-08-24
  • 打赏
  • 举报
回复
有没有纯粹些的代码?
511214 2003-08-24
  • 打赏
  • 举报
回复
<%
PgSz=10
Set Conn=Server.CreateObject("ADODB.Connection")
Set RS=Server.CreateObject("ADODB.RecordSet")
conn.Open "dsn=business;uid=businessuser;pwd=businessuser"
strsql="select a.*,b.mean from balancewastebook a,balancetype b where a.memberid="
strsql=strsql&session("memberid")&" and a.relationmanid="&session("relationmanid")
strsql=strsql&" and a.balancewastebookid=b.balancewastebookid"
RS.open strsql,Conn,1,1
If RS.RecordCount=0 then
response.write "<P><center>对不起,数据库中没有相关信息!</center></P>"
else
RS.PageSize = Cint(PgSz)
Total=INT(RS.recordcount / PgSz * -1)*-1
PageNo=Request("pageno")
if PageNo="" Then
PageNo=1
else
PageNo=PageNo+1
PageNo=PageNo-1
end if
ScrollAction=Request("ScrollAction")
if ScrollAction="上一页" Then
PageNo=PageNo-1
end if
if ScrollAction="下一页" Then
PageNo=PageNo+1
end if
if PageNo<1 Then
PageNo=1
end if
n=1
RS.AbsolutePage = PageNo
'Response.Write "<CENTER>"
position=RS.PageSize*PageNo
pagebegin=position-RS.PageSize+1
if position<RS.RecordCount then
pagend=position
else
pagend= RS.RecordCount
end if
'Response.Write "<P><font color='Navy' size=2><B>数据库查询结果:</B>"
Response.Write "<br><P><font color='Navy' size=2>(共有"&RS.RecordCount &"条符合条件的信息,显示"&pagebegin&"-"&pagend&")</font></p>"
%>
</div>
<TABLE WIDTH="64%" BORDER=1 align="center" CELLPADDING=2 CELLSPACING=0 BGCOLOR=#FFFFFF class="unnamed3">
<TR BGCOLOR=336699> <FONT SIZE=2>
<td width="18%" height="23" align="center"><font color="#FFFFFF">余额</font></td>
<td width="18%" align="center"><font color="#FFFFFF">服务费用</font></td>
<td width="18%" align="center"><font color="#FFFFFF">充值金额</font></td>
<td width="23%" align="center"><font color="#FFFFFF">余额类别</font></td>
<td width="23%" align="center"><font color="#FFFFFF">发生时间</font></td>
</FONT> </TR BGCOLOR=#FFFFFF>
<%
Do while not (RS is nothing)
RowCount=RS.PageSize
Do While Not RS.EOF and rowcount>0
If n=1 then
Response.Write "<TR BGCOLOR=#FFFFFF>"
ELSE
Response.Write "<TR BGCOLOR=#EEEEEE>"
End If
n=1-n
%>
<td width="18%" align="center"><%=rs("balance")%> </td>
<td width="18%" align="center"><%=rs("servicemoney")%> </td>
<td width="18%" align="center"><%=rs("fillmoney")%> </td>
<td width="23%" align="center"><%=rs("mean")%> </td>
<td width="23%" align="center"><%=rs("happenTime")%> </td>
<%
RowCount=RowCount-1
RS.MoveNext
Loop
set RS=RS.NextRecordSet
Loop
%>
</table>

<FORM METHOD=post action="--WEBBOT-SELF--">
<INPUT TYPE="HIDDEN" NAME="pageno" VALUE="<%=PageNo%>">
<%
if PageNo>1 Then
response.write "<INPUT TYPE=SUBMIT NAME=ScrollAction VALUE=上一页>"
end if
if RowCount=0 and PageNo<>Total then
response.write "<INPUT TYPE=SUBMIT NAME=ScrollAction VALUE=下一页>"
end if
response.write "<input type=button value=返回 name=B2 onclick=javascript:history.go(-1)>"
response.write "</FORM>"
End if
Conn.Close
set rs=nothing
set Conn=nothing
%>


bineon 2003-08-24
  • 打赏
  • 举报
回复
<div align="right">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="99%" id="AutoNumber21" height="90">
<tr>
<%
sql="select top 8 * from wenzhang where sh=0 and lanmu='"& lanmu &"' order by fen desc"
rs.open sql,conn,1,1
j=1
%>
<td width="100%" height="143"><%
do while not rs.eof
%><img border="0" src="face/<%=j%>.gif">
<a href="hit.asp?id=<%=rs("id")%>" target="_blank">
<%if len(rs("title"))<=8 then
response.write(rs("title"))
else response.write(left(rs("title"),8)&"…")
end if
response.write("<br>")
j=j+1
%> </a><% rs.movenext
loop%></td>
<%rs.close%>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="629" height="60" style="border-top-style: none; border-top-width: medium; border-bottom-style:none; border-bottom-width:medium">
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="96%" id="AutoNumber23" height="100%">
<tr>
<td width="53%"><img border="0" src="_images/main.jpg"></td>
<td width="13%"> </td>
<td width="34%"> </td>
</tr>
</table>
</center>
</div>
</td>
</tr>
<tr>
<td width="629" height="5" style="border-top-style: none; border-top-width: medium; border-bottom-style:none; border-bottom-width:medium"></td>
</tr>
<tr>
<td width="629" height="394" style="border-top-style: none; border-top-width: medium; border-bottom-style:none; border-bottom-width:medium" valign="top">
<div align="center">
<center>
<%
sql="select * from wenzhang where sh=0 and lanmu='"& lanmu &"' order by id desc"
rs.open sql,conn,1,1
if not rs.eof and not rs.bof then
rs.pagesize=18
pgnm=rs.pagecount
page=request.querystring("page")
if isempty(page) or cint(page)<1 or cint(page)>pgnm then
page=1
end if
rs.absolutepage=page
end if


count=0
%>

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="96%" id="AutoNumber22" height="49">
<tr>
<td width="43%" height="15" valign="bottom" style="font-size: 9pt; color: #000000; font-weight: bold">
文章名</td>
<td width="18%" height="15" valign="bottom" style="font-size: 9pt; color: #000000; font-weight: bold">
作者</td>
<td width="11%" height="15" valign="bottom" style="font-size: 9pt; color: #000000; font-weight: bold">
点击</td>
<td width="9%" height="15" valign="bottom" style="font-size: 9pt; color: #000000; font-weight: bold">
得分</td>
<td width="19%" height="15" align="right" valign="bottom" style="font-size: 9pt; color: #000000; font-weight: bold">时间</td>
</tr>
<tr>
<td width="100%" height="1" colspan="5"><hr color="#8293E6"></td>
</tr>
<% do while not rs.eof and count<>rs.pagesize %>
<tr>
<td width="43%" height="13" style="border-bottom-style: solid; border-bottom-width: 1" bordercolor="#F0F0FF" valign="bottom">
<a href="hit.asp?id=<%response.write rs("id")%>" target=_blank son="hint" alt="...<%=replace(left(rs("text"),90),"<br>",chr(13))%>..." style="behavior:url(htc/0007.htc)"><%response.write rs("title")%></a></td>
<td width="18%" height="13" style="border-bottom-style: solid; border-bottom-width: 1" bordercolor="#F0F0FF" valign="bottom"><%response.write rs("writer")%></td>
<td width="11%" height="13" style="border-bottom-style: solid; border-bottom-width: 1" bordercolor="#F0F0FF" valign="bottom"><%response.write rs("hits")%></td>
<td width="9%" height="13" style="border-bottom-style: solid; border-bottom-width: 1" bordercolor="#F0F0FF" valign="bottom"><%response.write rs("fen")%></td>
<td width="19%" height="13" align="right" style="border-bottom-style: solid; border-bottom-width: 1" bordercolor="#F0F0FF" valign="bottom"><%response.write replace(rs("now"),"-",".")%></td>
</tr>

<tr>
<td width="100%" height="9" colspan="5"></td>
</tr> <% rs.movenext
count=count+1
loop%>
<tr>

<td width="100%" height="16" colspan="5" align="center"><%if page=1 then%><p align="center">
<font color="#CCCCCC">上一页</font><%else%> <A href="more.asp?lanmu=<%=lanmu%>&page=<%=page-1%>">上一页</A><%end if%> 
<%if page\pgnm=0 then%><A href="more.asp?lanmu=<%=lanmu%>&page=<%=page+1%>">下一页</A><%else%> <font color="#CCCCCC">下一页</font><%end if%>
<font color="#FF0000"><%=lanmu%></font>共<font color="#FF0000"><%=rs.recordcount%></font>篇文章,每页<font color="#FF0000">18</font>篇,共<font color="#FF0000"><%=pgnm%></font>页,<span lang="zh-cn">当前为第<font color="#FF0000"><%=page%></font>页,</span>跳转到<select name="page" onChange="MM_jumpMenu('parent',this,0)" style="border:1px solid #8293E6; font-size: 9pt;width=62px;height=16px; color:#111111; background-color:#DDDDFF">
<option selected value="#">请选择</option>
<%for i=1 to rs.pagecount%>
<option value="more.asp?lanmu=<%=lanmu%>&page=<%=i%>">第<%=i%>页</option>
<%next%>
</select></td>
</tr>
</table>
</center>
</div>


你看看这个吧。我看了你的代码,由于以前没有用过rs.movefirst所以不是很清楚
不过我这个也很好用的!

28,390

社区成员

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

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