求助:请问使用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>共有 "&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>
[此贴子已经被作者于2006-5-21 18:36:13编辑过]