使用select top....方式分页时面页码出错,强烈求助!

atozxp 2006-05-26 01:47:09
求助:请问使用select top ..进行分页显示,点下一页时页码就直接跳到最后一页,且点上一页或首页均无效;如果屏蔽掉某段代码,就可以正常翻页,但在到达最后一页时点下一页时,当前页码数仍在继续增加,到底是哪儿出错了呢?还请各位指教!

直接走到最后一页的演示请见door.it50.net/page2/index.asp
屏蔽掉某段代码后的演示请见door.it50.net/page2/index1.asp

<!--#include file="conn.asp"-->
<!--#include file="css.asp"-->
</head>
<table width="600" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center">ID</div></td>
<td><div align="center">标题</div></td>
<td><div align="center">作者</div></td>
<td><div align="center">正文</div></td>
<td><div align="center">时间</div></td>
</tr>
<%
dim allcounts,counts,allpage,page,url,exec,jishu,sql
'allcounts是记录总数
'counts是每页显示的记录数
'allpage是总的页码
'page是sql中top xx的值
'url是显示记录的页面文件名
'jishu是页码

url="index.asp"
exec="select * from lyb"
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1

allcounts=rs.recordcount
counts=10

if cint(allcounts/counts)<(allounts/counts) then
allpage=(cint(allcounts/counts)+1)
'如果四舍五入后的页码小于原页码,则总页数等于四舍五入后的页码+1
else
allpage=cint(allcounts/counts)
end if

jishu=request("jishu")
response.Write(jishu)'获取当前页码

if not isnumeric(jishu) then
jishu=1
end if
' '如果页码数不全为数字,则设定页码为1
if jishu<1 then
jishu=1
' '如果page变量未被初始化或page变量四舍五入后小于1,则设page的值为1(预防走到头)
end if

if jishu>allpage then
jishu=allpage
end if
'屏蔽掉这段if就可以正常翻页但直至最后一页仍能够继续增加页码数------------------------------------------------------

response.Write(jishu)
page=counts*jishu


sql="select top "&counts&" b.* from (select top "&page&" id,id from lyb order by id desc) a,lyb b where b.id = a.id order by a.id"
set rs1=server.createobject("adodb.recordset")
rs1.open sql,conn,1,1

do while (not rs1.eof)
'如果数据库中有记录且设定的每页显示数量大于0
%>
<tr>
<td width="50"><div align="center"><%=rs1("ID")%></div></td>
<td width="50"><div align="center"><%=rs1("bt")%></div></td>
<td width="50"><div align="center"><%=rs1("zz")%></div></td>
<td width="50"><div align="center"><%=rs1("zw")%></div></td>
<td width="180"><div align="center"><%=rs1("times")%></div></td>
</tr>
<%
rs1.movenext
if rs1.eof then exit do
loop
%>
</table>

<table align="center">
<tr>
<td width="600" align=right valign="bottom" class="STYLE3" headers="50"><table width="600" height="56" border="0" align="center" cellspacing="3" class="STYLE3">
<tr>
<td height="46" align="right" valign="top">
<%
'显示总条数
response.Write("<br/>共有 "&allcounts&"条记录,")

if jishu=1 then
response.Write("首页 上一页 ")
else
response.Write "<a href=index.asp?jishu=1>首页</a> <a href=index.asp?jishu="&jishu-1&">上一页</a> "
end if
'页码为1时首页/上一页不加链接,否则加链接

if jishu=allpage then
response.Write "下一页 末页"
else
response.Write "<a href=index.asp?jishu="&jishu+1&">下一页</a> <a href=index.asp?jishu="&allpage&">末页</a> "
end if
response.Write ",当前位于第"&jishu&"页,共"&allpage&"页"
%>
</td>
</tr>
</table></td>
...全文
142 3 打赏 收藏 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gsyst520 2006-05-26
  • 打赏
  • 举报
回复
jishu=request("jishu")

--------------------------
jishu=request("jishu")
if jishu="" or jishu&"a"="a" or (not isnumeric(jishu)) then
jishu=1
else
jishu=cint(jishu)
end if
「已注销」 2006-05-26
  • 打赏
  • 举报
回复
对

if not isnumeric(jishu) then
jishu=1
end if

后面加上

jishu=cint(jishu)
mrwang2000 2006-05-26
  • 打赏
  • 举报
回复
个人意见,仅供参考

asp是弱类型语言,
在进行数值计算和数值比较时,记得用 CInt()

28,402

社区成员

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

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