分页显示的问题?

huaxiaosxl 2002-06-03 12:27:38
如何实现分页显示时只从数据库查询出当前页的记录而不是全部记录?

好像是用 SELECT TOP 语句,但我不知具体该如何?

例如:现在是第5页,每页显示20条记录,那么该SQL语句该如何写?

SELECT TOP ...???
...全文
44 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
huaxiaosxl 2002-06-03
  • 打赏
  • 举报
回复
TO:秦汉风
这样子返回的记录集只会当前页的吗?
谢谢!
MeXP 2002-06-03
  • 打赏
  • 举报
回复
更正
sqlstr="select top "&session("pagesize")*session("pageno")&" * from table"
MeXP 2002-06-03
  • 打赏
  • 举报
回复
sqlstr="select top "&session("pagesize")*session("pageno")&" from table"
ywz413 2002-06-03
  • 打赏
  • 举报
回复
http://www.csdn.net/expert/topic/762/762206.xml?temp=.4681055
saucer 2002-06-03
  • 打赏
  • 举报
回复
Paging through Records using a Stored Procedure
http://www.4guysfromrolla.com/webtech/062899-1.shtml
Bullforg 2002-06-03
  • 打赏
  • 举报
回复
选择条件的问题

sql="select * from Table where XX LIKE '%"&trim(request("keyword"))&"%' order by id desc"
hn82123 2002-06-03
  • 打赏
  • 举报
回复
select 可以,完整代码:
<%
pageSize=20

currentPage=trim(request.querystring("page"))
if isNumeric(currentPage) then
currentPage=cInt(currentPage)
if currentPage<1 then currentPage=1
else
currentPage=1
end if

sqlstr="select count(id) as totalRs from newsTopic"
set rs=conn.execute(sqlstr)
totalRs=rs("totalRs")
rs.close
totalPage=totalRs\pageSize+1
if currentPage>totalPage then currentPage=totalPage
headRs=pageSize * (currentPage-1)

sqlstr="select top " & pageSize & " id,topicName,working,setupTime from newsTopic where id not in(select top " & headRs & " id from newsTopic order by id desc) order by id desc"
set rs=conn.execute(sqlstr)
%>
ehom 2002-06-03
  • 打赏
  • 举报
回复
你不用争,你自己写代码测下执行时间,测下内存占用!事实证明一切!
Lzh_lee 2002-06-03
  • 打赏
  • 举报
回复
select top 20 from ……,你不是说这个吧?嘻嘻,楼上这位同学你说到执行效率,但是你又知道select top 20 from ……这种语句执行效率又有多高呢?如果想不返回全部数据就可以用存储过程分页的方法,代码太长了不贴。其实huaxiaosxl (Ken Lee)你说的问题一样是用ado分页的方法来做的。比如RsInspect.AbsolutePage=5,你设置absolutepage的值就可以设置显示的页了。
ehom 2002-06-03
  • 打赏
  • 举报
回复
老老实实写个分页的代码?

那种老老实实的代码谁不会?
看来你们写ASP程序不考虑执行效率问题!数据量很大时,为了显示一页数据返回全部数据?那么多无关数据!而Bullforg(回廊) 朋友居然写 select * ,确不知此乃大忌!!!看来朋友们需要在很多细节上多做研究,虽然看起来实现的效果差不多!
BrightEye 2002-06-03
  • 打赏
  • 举报
回复
select top .......行吗????????????不行吧.
还是老老实实写个分页的代码吧.论坛里好多这样的帖子.
BrightEye 2002-06-03
  • 打赏
  • 举报
回复
select top .......行吗????????????不行吧.
还是老老实实写个分页的代码吧.论坛里好多这样的帖子.
wangfei2428 2002-06-03
  • 打赏
  • 举报
回复
select top n 表示抽取满足条件的记录集其中n条记录,而与分页好象没有多大的关系
至于分页的程序,您下载一个,然后自己慢慢研究,有看不懂的地方再来提问
ehom 2002-06-03
  • 打赏
  • 举报
回复
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
liuzxit 2002-06-03
  • 打赏
  • 举报
回复
單純用SELECT TOP不行的﹐不過論壇上有很多相關貼子﹐你自己搜索吧﹐上面也貼了不少連接
ehom 2002-06-03
  • 打赏
  • 举报
回复
以前就回复过很多次了,在论坛里找!
http://www.csdn.net/expert/topic/529/529126.xml

28,390

社区成员

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

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