| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1185 人关注过本帖
标题:使用select top....方式分页时面页码出错,求助!
只看楼主 加入收藏
atozxp
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-4-9
收藏
 问题点数:0 回复次数:9 
使用select top....方式分页时面页码出错,求助!

求助:请问使用select top ..进行分页显示时点下一页时页码page=xx就直接跳到最后一页,但显示的内容并不是最后一页的内容,且点上一页或首页均无效,到底是哪儿出错了呢?还请各位指教!

具体演示请见door.it50.net/page2/index.asp

<!--#include file="conn.asp"-->
<!--#include file="css.asp"-->

</head>
<table width="600" border="1" align="center" cellpadding="0" cellspacing="0" class="STYLE3">
<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=1
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 rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1

jishu=request("jishu")
'获取当前页码
if not isnumeric(jishu) then
jishu=1
end if
'如果页码数不全为数字,则设定页码为1
if jishu<1 then
jishu=1
'如果page变量未被初始化或page变量四舍五入后小于1,则设page的值为1(预防走到头)
elseif jishu>=allpage then
jishu=allpage
end if
'否则,如果page变量四舍五入后大于等于总页码,则设page变量的值为总页码(预防走到尾)

do while (not rs.eof) and counts>0
'如果数据库中有记录且设定的每页显示数量大于0
%>
<tr>
<td width="50"><div align="center"><%=rs("ID")%></div></td>
<td width="50"><div align="center"><%=rs("bt")%></div></td>
<td width="50"><div align="center"><%=rs("zz")%></div></td>
<td width="50"><div align="center"><%=rs("zw")%></div></td>
<td width="180"><div align="center"><%=rs("times")%></div></td>
</tr>
<%
rs.movenext
if rs.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>共有&nbsp;"&allcounts&"条记录,")

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

if jishu=allpage then
response.Write "下一页 末页"
else
response.Write "<a href=index.asp?jishu="&jishu+1&">下一页</a>&nbsp;<a href=index.asp?jishu="&allpage&">末页</a>&nbsp;"
end if
response.Write ",当前位于第"&jishu&"页,共"&allpage&"页"
%>
</td>
</tr>
</table></td>

[此贴子已经被作者于2006-5-21 18:36:13编辑过]

搜索更多相关主题的帖子: 页码 select top 
2006-05-21 18:34
hangxj
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2045
专家分:0
注 册:2006-4-10
收藏
得分:0 
以下是引用atozxp在2006-5-21 18:34:00的发言:

求助:请问使用select top ..进行分页显示时点下一页时页码page=xx就直接跳到最后一页,但显示的内容并不是最后一页的内容,且点上一页或首页均无效,到底是哪儿出错了呢?还请各位指教!

具体演示请见door.it50.net/page2/index.asp

<!--#include file="conn.asp"-->
<!--#include file="css.asp"-->

</head>
<table width="600" border="1" align="center" cellpadding="0" cellspacing="0" class="STYLE3">
<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=1 在这你已经定义了jisgu 和 page 的值
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 rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1

jishu=request("jishu")
'获取当前页码
if not isnumeric(jishu) then
jishu=1
end if
'如果页码数不全为数字,则设定页码为1
if jishu<1 then
jishu=1
'如果page变量未被初始化或page变量四舍五入后小于1,则设page的值为1(预防走到头)
elseif jishu>=allpage then
jishu=allpage
end if
'否则,如果page变量四舍五入后大于等于总页码,则设page变量的值为总页码(预防走到尾)

do while (not rs.eof) and counts>0
'如果数据库中有记录且设定的每页显示数量大于0
%>
<tr>
<td width="50"><div align="center"><%=rs("ID")%></div></td>
<td width="50"><div align="center"><%=rs("bt")%></div></td>
<td width="50"><div align="center"><%=rs("zz")%></div></td>
<td width="50"><div align="center"><%=rs("zw")%></div></td>
<td width="180"><div align="center"><%=rs("times")%></div></td>
</tr>
<%
rs.movenext
if rs.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>共有&nbsp;"&allcounts&"条记录,")

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

if jishu=allpage then
response.Write "下一页 末页"
else
response.Write "<a href=index.asp?jishu="&jishu+1&">下一页</a>&nbsp;<a href=index.asp?jishu="&allpage&">末页</a>&nbsp;"
end if
response.Write ",当前位于第"&jishu&"页,共"&allpage&"页"
%>
</td>
</tr>
</table></td>



http://www./
2006-05-22 09:04
atozxp
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-4-9
收藏
得分:0 
那这两个值总得有个初始值吧?或者说,这个赋值放在哪儿比较合适?
2006-05-22 21:31
atozxp
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-4-9
收藏
得分:0 
自己顶一下!
2006-05-23 21:33
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 

为什么要用select top分页,用rs的内置方法不能分页么?

2006-05-23 21:43
atozxp
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-4-9
收藏
得分:0 
听说用select top方式速度要比rs方式快,想尝试并测试一下,而且我的服务器比较慢,在数据量达到8000多条时就明显的不行了
2006-05-23 21:54
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
exec="select * from lyb"
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
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 rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
两次打开了rs没有关闭。
2006-05-23 22:06
zfjyyzycl
Rank: 2
等 级:论坛游民
帖 子:239
专家分:10
注 册:2006-4-15
收藏
得分:0 
不错!要及时的关闭打开的记录集,否则就是1个G的内存也会很快被消耗掉
rs.close
set rs=nothing
2006-05-23 22:46
魔风
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2006-3-7
收藏
得分:0 
   说的没错  不过我分页基本上就用的RS

2006-05-24 00:18
atozxp
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-4-9
收藏
得分:0 

rs.close
set rs=nothing
我已经加了,可是对于分页错误不起什么作用呀!

我发现,只要有下面的句子,就会出错,可是不加这个在到达最后一页时还可以继续的向下翻页,虽然内容不会动,但页码计算在不停的走。到底是哪儿的原因呢?

if jishu>allpage then
jishu=allpage
end if

[此贴子已经被作者于2006-5-24 0:35:15编辑过]

2006-05-24 00:23
快速回复:使用select top....方式分页时面页码出错,求助!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028725 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved