为什末不能分页呀?

wishingwings 2003-08-14 11:51:18
写了一个查询的分页程序,为什末不能分页?请大侠们帮我看看?谢谢了

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>lendbook</title>
</head>

<body>
<%
dim counter
dim m,n,i
Set conn=server.CreateObject("ADODB.Connection")
conn.open "dsn=bookmanage"

Set count=conn.Execute("select * from book where state='1' " )
Do while not count.eof
counter=counter+1
count.movenext
loop
Set rs=Server.CreateObject("ADODB.Recordset")
sql="select * from book where state='1' "
rs.Open sql,conn,1,1
%>
<form name="notlend_book" method="post" action=" borrow_book .asp">
<table width="100%" height="100" border="0">
<tr style="BACKGROUND-COLOR: cornsilk"> 未借出图书</font></tr>
请选择您需要借阅的图书确定后 按下“提交”按钮。
<tr style="BACKGROUND-COLOR: cornsilk">
<td align="center" width="7%" > 图书序号</td>
<td align="center" width="8%" > 图书编号</td>
<td align="center" width="38%"> 图书名称</td>
<td align="center" width="20%">图书作者</td>
<td align="center" width="10%">出版社</td>
</tr>
<% rs.pagesize=10
rs.absolutepage=request.querystring("Pcnt")
for m=1 to rs.pagesize
if rs.eof then
exit for
end if
%>
<% do while not (rs.eof or err)%>
<tr style="BACKGROUND-COLOR: cornsilk">
<td ><input type="radio" name="bookchange" value="<%=rs(0)%>"><%=rs(0)%></td>
<% for i=1 to 4%>
<td style="BACKGROUND-COLOR: cornsilk" valign="center" align="left" width="15%">
<%=rs(i)%>
</td>
<%next%>
</tr>
<%rs.MoveNext
loop %>
<%next%>


<tr>
<input name="submit" type="button" value="提交"> <input name="cancel" type="button" value="取消">
</tr>
<tr>
<td colspan="4">目前有<%=rs.pagecount%>页 共<%=counter%>条记录</td></tr>
<tr>
<td>
<%
for n=1 to rs.pagecount
%>
<a href="numberpage.asp?Pcnt=<%=n%>"><%=n%></a>
<%next%>
<% rs.close
set conn=nothing
%>
</td></tr>
</table>

</form>

</body>

</html>
...全文
55 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
mzcih 2003-12-14
  • 打赏
  • 举报
回复
为什么是20*4与20*5呢?
超级大笨狼 2003-12-14
  • 打赏
  • 举报
回复

ASP学习史上最强的数据分页方法

  我观前辈的帖子,皆由于数据库的SQL大不一致,且SQL SERVER,ACCESS等菜鸟级数据库没有如rowid,_n_,obs等之类的辅助列,空有BETWEEN运算符而无用武之地,
又无如except之类的数据集运算符,真是令无数英雄尽折腰



  偶详观各数据库SQL,得出是数据库就有取前面N条记录的SQL语法,如什么select top n*****之类的语法,而数据分页的关键问题是取后N条记录的语法偶深思良久,最后小悟,故出此言,还忘前辈们多多指点
  
  取记录集后N条记录的大法:
  
  假设:
  
   1.有一sql语句将产生1000条记录 (select 唯一ID,其他字段 from 表集 where 条件 order by 排序)
   2.每页显示20条记录
   3.当前显示第5页
  
  实现如下:
   select * from
   (
   select * from (select top 20*4 唯一ID,其他字段 from 表集 where 条件 order by 排序) as a
   union all
   select * from (select top 20*5 唯一ID,其他字段 from 表集 where 条件 order by 排序) as b
   )
   a
   group by 唯一ID,其他字段 having count(唯一ID)=1 order by 排序
  
  运行此SQL,至此取记录集后N条记录大法就些完毕
  
  详细说明:
  
  此SQL语句的关键应用技巧在于union all和分组上的条件过滤语句
  
  大家可以根据此技巧完全可以做出一个通用的分页方法,如直接由用户传入sqlstr(sql语句),NumPerPage(每页显示数),currpage(当前页),自己在再函数内组织成通成的SQL分页语句
  
  备注:
  
  当前页为1的话就不需要运行该SQL了,直接TOP一下就OK了
  由于没有环境,该SQL性能无法测试,但相信不会低效
  运行平台在access,sqlserver上都可运行,其它数据库平台只需改top关键字应该就可以就地运行了





LonelyStark 2003-08-14
  • 打赏
  • 举报
回复
给你看偶的例子
<!--#include file="conn.asp"-->

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<%
if isnumeric(request.querystring("page")) then
page=clng(request.querystring("page"))
else
page=1
end if
if page<1 then page=1
set rs=server.createobject("adodb.recordset")
rs.open "select * from statistics_login order by login_time desc",MyCon,1,1
rs.absolutepage=page
rs.cachesize=50%>
</head>

<center>
<b><span style="font-size: 11pt">用户访问查看信息</span></b>
<p><span style="font-size:9pt">
截至今天<%=year(date())%>年<%=month(date())%>月<%=day(date())%>日为止 本站共<%=rs.recordcount%>人次访问
</span></p>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="700" id="AutoNumber1" height="21">
<tr>
<td style="font-size: 9pt" align="center" height="21" width="106" bgcolor="#BFEBFF">ID</td>
<td style="font-size: 9pt" align="center" height="21" width="197" bgcolor="#BFEBFF">用户的真实IP地址</td>
<td style="font-size: 9pt" align="center" height="21" width="197" bgcolor="#BFEBFF">用户使用的代理服务器IP地址</td>
<td style="font-size: 9pt" align="center" height="21" width="197" bgcolor="#BFEBFF">用户访问的时间</td>
</tr>
<%do while not rs.eof%>
<tr>
<td style="font-size: 9pt" align="center" height="21" width="106"><%=rs("id")%></td>
<td style="font-size: 9pt" align="center" height="21" width="197"><%=rs("real_ip")%></td>
<td style="font-size: 9pt" align="center" height="21" width="197"><%=rs("agent_ip")%></td>
<td style="font-size: 9pt" align="center" height="21" width="197"><%=rs("login_time")%></td>
</tr>
<%rs.movenext
loop%>
</table>
<p><span style="font-size:9pt">
共<font color=red><b><%=rs.pagecount%></b></font>页 当前第<font color=red><b><%=page%></b></font>页
<%if page<=1 then%>
首页 上页
<%else%>
<a href="admin_counter.asp?page=1">首页</a>
<a href="admin_counter.asp?page=<%=page-1%>">上页</a>
<%end if%>
<%if page>=rs.pagecount then%>
下页 末页
<%else%>
<a href="admin_counter.asp?page=<%=page+1%>">下页</a>
<a href="admin_counter.asp?page=<%=rs.pagecount%>">末页</a>
<%end if%></span>
<span style="font-size: 9pt">
到第 <input type="text" name="txtpage" size="4" style="font-size: 9pt; border: 1px solid #000000"> 页
</span>
<input type="button" value=" GO " name="btnGo" style="font-size: 9pt; border: 1px solid #000000; background-color: #BFEBFF"></p>
<script language=vbs>
sub btnGo_onclick()
if isnumeric(txtpage.value) then
window.location.href="admin_counter.asp?page="&txtpage.value
else
msgbox "请填入页面数字!"
end if
end sub
</script>

28,391

社区成员

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

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