如何数据分页显示……

LYSSHE 2002-01-30 06:19:51
请问如何把数据表中的记录分页显示就像当前页面的的[1][2][3]……一样
我想应该用ado的recordset的pagesize 与pagecount相配合吧?
可是具体实现算法应该怎样,我不知道。比如当我点击“[10]”时怎么知道是第十页呢?
请GGMM们指教
...全文
63 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ashaioo 2002-01-30
  • 打赏
  • 举报
回复
给你介绍一个非常方便的软件,可以直接实现分页功能

aspmaker

忘记在那里可以下载了,你自己去找找,很小的程序
ehom 2002-01-30
  • 打赏
  • 举报
回复
此帖怎么到处发?

“我想应该用ado的recordset的pagesize 与pagecount相配合吧?”

此方法不好!不管是第几页,都需要返回整个记录集再分页!比如你的数据库有10000条记录,而你想看第一页的10条,确也需要先返回10000条!所以应该根据页码确定要返回的记录,这样效率较高!

给段示例代码(部分):

dim pagenum
dim topnum
dim totalrec
pagenum=request.querystring("page")
if pagenum="" then pagenum=1
if not IsNumeric(pagenum) then pagenum=1
if pagenum=<0 then pagenum=1
if pagenum>99999 then pagenum=1
pagenum=fix(pagenum)
topnum=pagenum*20
sql="select top "&topnum&" ID,date,title from article where type="&ID
rs.open sql,arconn,1,1
totalrec=rs.recordcount
if (totalrec mod 20)=0 then
lastpage=totalrec\20
else
lastpage=totalrec\20+1
end if
if (pagenum-1)*20>=totalrec then
if (totalrec mod 20)=0 then
pagenum=totalrec\20
else
pagenum=totalrec\20+1
end if
end if
if not pagenum=1 and (pagenum-1)*20<totalrec then
rs.move (pagenum-1)*20
else
pagenum=1
end if

而想知道点什么,可以这样做!如点[10],其HTML代码为:
<a href="page.asp?page=10">[10]</a>,而实际实现时用for循环得到!
如:
<%
for n=1 to 10
response.write "<a href='page.asp?page="&n&"'>["&n&"]</a>"
next
%>
希偌 2002-01-30
  • 打赏
  • 举报
回复
一个例子:
<!--#include file="./include/conn.inc"-->

<%
const intpagesize=20
if Request("page")="" then
intcur=1
else
select case request("page")
case "first"
intcur=1
case "previous"
intcur=cint(request("curpage"))
intcur=intcur-1
case "next"
intcur=cint(request("curpage"))
intcur=intcur+1
case "last"
intcur=cint(request("lastpage"))
case else
intcur=request("page")
end select
end if
set rst=server.createobject("ADODB.recordset")
rst.CursorLocation=2
rst.CursorType=3
rst.CacheSize=intpagesize
straccess="select * from law where answer is not null and not answer like ''"
rst.open straccess,strconn
rst.PageSize=intpagesize
if Not rst.EOF then
rst.AbsolutePage=intcur
end if
inttotal=rst.pagecount
session("inttotal")=inttotal
rscount=rst.recordcount
%>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>法律咨询</title>
<style TYPE="text/css">
<!--

BODY {FONT-FAMILY: "宋体", "宋体"; FONT-SIZE: 9pt; LINE-HEIGHT: 12pt}
BR {FONT-FAMILY: "宋体", "宋体"; FONT-SIZE: 9pt; LINE-HEIGHT: 12pt}
TD {FONT-FAMILY: "宋体"; FONT-SIZE: 9pt; LINE-HEIGHT: 12pt}


a {COLOR: #000080; text-decoration: none}
a:hover {color:#ff0000;text-decoration:none}
.submit {line-height:9pt;font-size:9pt;font-family:宋体}
.submit1 {line-height:8pt;font-size:8pt;font-family:宋体}
.selectform {font-family: 宋体; font-size: 9pt;background-color:ffE4E4}
.td {font-family: 宋体; font-size: 9pt;background-color:#EEEEEE}
.td1 {font-family: "宋体"; font-size: 9pt;background-color:#dddddd}
.td2 {font-family: 宋体; font-size: 9pt;background-color:#EEEEEE}
.small1 {font-family: 宋体; font-size: 9pt;background-color:ffffff;line-height:9pt}
-->
</style>
</head>

<body bgcolor=#ffffff leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!--#include file="./include/top.asp"-->
<table width="780">
<tr>
<td width="140">(1)专利申请方法、手续办理通知(通告形式);<br><br>
(2)专利技术特点、易出现问题和须注意的问题;<br><br>
(3)中、外专利法规;<br><br>
(4)专利技术交易成功案例;<br><br>
(5)专利问答。
</td>
<td width="17" valign="top" background="../image/idx_split_v.gif"> </td>
<td width="600"> <br>
<center><font color="#ff0000" face="楷体_GB2312" size="4">法律咨询</font></center>
<center>
<table border="0.1" cellPadding="0" cellSpacing="1" width="100%" bordercolorlight="#0000FF">
<tbody>
<tr>
<td width="22%">【<a href="write.asp">我要提问</a>】</td>
<td width="78%">
<p align="right"><img src="images/ico.gif">总页数: <font color="red"><% =inttotal %>
</font>   <img src="images/amount.gif"> 论题数: <font color="red"><% =rst.recordcount %>
</font>   <img src="images/curpage.gif"> 当前页数: <font color="red"><% =intcur %>
</font>   </p>
</td>
</tr>
</tbody>
</table>
<div align="center">
<center>
<table border="0" cellPadding="1" cellSpacing="1" width="100%" bgcolor="#cccccc">
<tr bgcolor="#000000">
<td align="middle" class="td1" height="15" width="62"><font color="#000000">序号</font></td>
<td align="middle" class="td1" height="20" width="424"><font color="#000000">主   题</font></td>
<td align="middle" class="td1" height="15" width="98"><font color="#000000">点击</font></td>
<td align="middle" class="td1" height="15" width="98"><font color="#000000">提问人</font></td>
<td align="middle" class="td1" height="15" width="218"><font color="#000000">提问时间</font></td>
<td align="middle" class="td1" height="15" width="105"><font color="#000000">回复专家</font></td>
<td align="middle" class="td1" height="15" width="47"><font color="#000000">字数</font></td>
</tr>
<%
i=0
do while not rst.eof and i<rst.PageSize
%>
<tr>
<td onmouseover="this.style.background='#ffffff'" onmouseout="this.style.background='#eeeeee'" align="middle" bgColor="#004e9b" class="td" height="15" width="62"><font color="#000000"><% =rst("id") %></font></td>
<td onmouseover="this.style.background='#ffffff'" onmouseout="this.style.background='#eeeeee'" align="middle" bgColor="#004e9b" class="td" height="20" width="424"><font color="#000000"><a href="read.asp?id=<% =rst("id") %>" target="_blank"><% =rst("title") %></a></font></td>
<td onmouseover="this.style.background='#ffffff'" onmouseout="this.style.background='#eeeeee'" align="middle" bgColor="#004e9b" class="td" height="15" width="98"><font color="#000000"><% =rst("point") %></font></td>
<td onmouseover="this.style.background='#ffffff'" onmouseout="this.style.background='#eeeeee'" align="middle" bgColor="#004e9b" class="td" height="15" width="98"><font color="#000000"><% =rst("question_man") %></font></td>
<td onmouseover="this.style.background='#ffffff'" onmouseout="this.style.background='#eeeeee'" align="middle" bgColor="#004e9b" class="td" height="15" width="218"><font color="#000000"><% =rst("addtime") %></font></td>
<td onmouseover="this.style.background='#ffffff'" onmouseout="this.style.background='#eeeeee'" align="middle" bgColor="#004e9b" class="td" height="15" width="105"><font color="#000000"><% =rst("answer_man") %></font></td>
<td onmouseover="this.style.background='#ffffff'" onmouseout="this.style.background='#eeeeee'" align="middle" bgColor="#004e9b" class="td" height="15" width="47"><font color="#000000"><% =len(rst("question")) %></font></td>
</tr>
<%
i=i+1
rst.movenext
loop
%>

</table>
</center>
</div><br>
<center>
<table border="0" cellPadding="0" cellSpacing="1" width="100%" height="1" bgcolor="#cccccc">
<tbody>
<tr bgcolor="#006600">
<td align="middle" bgColor="#004e9b" class="td1" height="18" width="86"><font color="#000000">总页数</font></td>
<td align="middle" bgColor="#004e9b" class="td1" height="18" width="86"><font color="#000000">论题数</font></td>
<td align="middle" bgColor="#004e9b" class="td1" height="18" width="86"><font color="#000000">每页显示数</font></td>
<td align="middle" bgColor="#004e9b" class="td1" height="18" width="86"><font color="#000000">当前页数</font></td>
<td align="middle" bgColor="#004e9b" class="td1" height="18" width="87"><font color="#000000">页数</font></td>
<td align="middle" bgColor="#004e9b" class="td1" height="18" width="87"><font color="#000000">首页</font></td>
<td align="middle" bgColor="#004e9b" class="td1" height="18" width="87"><font color="#000000">末页</font></td>
<td align="middle" bgColor="#004e9b" class="td1" height="18" width="87"><font color="#000000">上一页</font></td>
<td align="middle" bgColor="#004e9b" class="td1" height="18" width="87"><font color="#000000">下一页</font></td>
</tr>
<tr>
<td align="middle" class="td" width="86" height="1"><% =inttotal %>
</td>
<td align="middle" class="td" width="86" height="1"><% =rst.recordcount %>
</td>
<td align="middle" class="td" width="86" height="1"><% =intpagesize %>
</td>
<td align="middle" class="td" width="86" height="1"><% =intcur %>
</td>
<td align="middle" class="td" vAlign="middle" width="87" height="1">
<form name="inputform">
<select name="sel" onchange="goto();" size="1">
<option selected>跳转页数</option>
<%
aaa=0
DO WHILE NOT aaa = rst.pagecount %>

<option value="index.asp?Page=<% =aaa+1 %>&curpage=<% =intcur %>"><% =aaa+1 %></option>

<% aaa=aaa+1
loop
%>
</select></form></td>
<td align="middle" class="td" width="87" height="1">【<a href="index.asp?page=first">首页</a>】</td>
<td align="middle" class="td" width="87" height="1">【<a href="index.asp?page=last&lastpage=<% =inttotal %>">末页</a>】</td>
<td align="middle" class="td" width="87" height="1">【<% if intcur>1 then %><a href="index.asp?page=previous&curpage=<% =intcur %>">上一页</a><% else response.write "上一页" end if %>】</td>
<td align="middle" class="td" width="87" height="1">【<% if intcur<inttotal then %><a href="index.asp?page=next&curpage=<% =intcur %>">下一页</a><% else response.write "下一页" end if %>】
</td>
</tr>
</tbody>
</table>
</center>
</center>
<div align="center">
<center>
<table border="0" cellPadding="0" cellSpacing="0" width="100%">
<tbody>
<tr>
<td width="100%"> </td>
</tr>
<tr>
<td width="100%">
<p align="center">
点击<a href="javascript:a();">这里</a>进入管理
</p>
</td>
</tr>
</tbody>
</table>
</center>
</div>
</td></tr></table>
<!--#include file="./include/bottom.asp"-->
</body>

</html>
<script>
<!--
function a() {window.open('manage.asp','','toolbar=no,scrollbars=no,width=250,height=350,resizable=no');}
function goto() {window.location.href=document.inputform.sel.value;}
//-->
</script>

28,406

社区成员

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

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