一段错误的分页程序,请大家解决。悬赏100分!

sa2000 2005-06-06 02:41:45
以下份页代码实行中有错误,请大家看看,万望解决!
<table width="80%" border="0" cellspacing="1" cellpadding="5">
<%
if not isempty(request("page")) then
Page=cint(request("page"))
else
Page=1
end if

set rs1=server.createobject("adodb.recordset")
sql1 ="select * from news"
rs1.open sql1,secondconn,1,1

if rs1.eof and rs1.bof then
response.write "<p align='center'>【<a href='javascript:window.close()'>关闭窗口</a>】"
else
const maxperpage=10
rs1.pagesize=maxperpage
totalrecord=rs1.recordcount
totalpage=rs1.pagecount
if page>totalpage then page=totalpage
rs1.absolutepage=page
i=0
dim id(),newstitle(),newstime(),newsauthor()
do while not rs1.eof and (i<=rs1.pagesize)
i=i+1
redim preserve id(i),newstitle(i),newstime(i),newsauthor(i)
id(i)=rs1("id")
newstitle(i)=rs1("newstitle")
newstime(i)=year(rs1("newstime"))&"年"&month(rs1("newstime"))&"月"&day(rs1("newstime"))&"日"
newsauthor(i)=rs1("newsauthor")
rs1.movenext
loop
end if
rs1.close
set rs1=nothing
%>
<%for i = 1 to totalrecord%>
<tr>
<td width="4%"><li></td>
<td width="55%"><div align="left"><a href="view.asp?id=<%=id(i)%>" target="_blank"><%=newstitle(i)%></a></div></td>
<td width="22%"><div align="left"><%=newstime(i)%></div></td>
<td width="19%"><div align="left"><%=newsauthor(i)%></div></td>
</tr>
<%next%>
</table>
...全文
182 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sa2000 2005-06-06
  • 打赏
  • 举报
回复
liveam(思梦)
你的方法很好,就是翻页后没有数据记录显示出来,为什么?
asp1113 2005-06-06
  • 打赏
  • 举报
回复
同学们我们需要这样的服务!!
100MB asp和 asp.net空间 50/1年
我看到了一个网站 100MB asp和 asp.net空间 现在促销,
同学们可以做一个简单的个人网站用来找工作 ,
支持 asp.net 一年才50元!不要错过哦!!!
速度非常快,一般公司企业 足够用了!
http://www.hi876.com
希望能对大家有帮助
liveam 2005-06-06
  • 打赏
  • 举报
回复
<%for i = 1 to totalrecord%>
<tr>
<td width="4%"><li></td>
<td width="55%"><div align="left"><a href="view.asp?id=<%=id(i)%>" target="_blank"><%=newstitle(i)%></a></div></td>
<td width="22%"><div align="left"><%=newstime(i)%></div></td>
<td width="19%"><div align="left"><%=newsauthor(i)%></div></td>
</tr>
<%next%>


其中:
for i=1 to totalrecord
改为:
thispagerecord=page*maxperpage
if thispagerecord>totalrecord then
thispagerecord=totalrecord
end if
for i=(page-1)*maxperpage+1 to thispagerecord



呵呵
freshui 2005-06-06
  • 打赏
  • 举报
回复
:) 顺便给你一小段首页 上一页 下一页 尾页 的链接代码吧 :)
总记录:<%=totalrecord%> 总页数:<%=totalpage%> 第<%=page%>页 <font color="#000000">
<% if page>1 then
response.write "【 <a href=?page=1"&">首页</a>"
response.write "|<<</font> <a href=?page="&(page-1)&">上一页</a> "
%>
<% else
response.write("【首页")
response.write(" |<<上一页")

end if%>
|
<% if page<totalPage then
response.write "<a href=?page="&(page+1)&">下一页</a>>>|"

response.write "<a href=?page="&totalPage&">末页</a>】"
%>
<% else
response.write("下一页>>|")
response.write("末页】")
end if %>
xumw 2005-06-06
  • 打赏
  • 举报
回复
哪能改为 <%for i = 1 to 10%> 这样的循环是死的了。
给你一段代码参考,感觉你的代码稍微有点乱;

rs1.pagesize=10
totalrecord=rs1.recordcount
totalpage=rs1.pagecount
page=int(request.QueryString("page"))
if page<=0 then page=1
if request.QueryString("page")="" then page=1
if not rs1.eof then //注意这里的判断,如果你不进行判断的话,当没有记录时会出错
rs.absolutepage=page
else
end if


<% for i=1 to rs.pagesize %>
…………
…………
<% rs.movenext
if rs.eof then exit for
next
end if
%>

首页 上一页 下一页 尾页 的链接自己判断一下吧,上面所有代码的意思,我想楼主应该明白,可以看得懂。
sa2000 2005-06-06
  • 打赏
  • 举报
回复
问题不是这样的,是我用这段程序分页时产生问题,本来每页要求显示10条,可每页却显示所有记录,若把<%for i = 1 to totalrecord%>改为<%for i = 1 to 10%>却会领第二页显示出空的记录(如标题前设的图片等)
xumw 2005-06-06
  • 打赏
  • 举报
回复
如果不行在改为
<%
rs.movenext
if rs.eof then exit for //移到下一条记录后,在退出一下循环,最后 next 退出
next
%>

还有楼主,你的错误信息都没有说,我看的错误不知道是不是你要的错误???
xumw 2005-06-06
  • 打赏
  • 举报
回复
到数第二句改为:

<% rs.movenext //你都不移到下一条记录,怎么循环呢。
next
%>

28,406

社区成员

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

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