| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2431 人关注过本帖
标题:ASP分页的原理是什么?
只看楼主 加入收藏
mjb115889
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-6-11
收藏
 问题点数:0 回复次数:16 
ASP分页的原理是什么?

写一个分页一定要用到下面这些属性吗

AbsolutePage :当前记录在总页面中的页数编号
AbsolutePosition : 绝对位置
PageCount : 数据存在的页数
PageSize :每页记录数
RecordCount :统计记录集的记录总数
rs.recordcount : 返回记录总数

我看到有些分页不用这些属性也可以呢?
代码看不懂 ,想知道分页的思路和原理是什么?

搜索更多相关主题的帖子: 原理 ASP 属性 记录 AbsolutePage 
2007-07-09 14:37
ASP汽车
Rank: 1
等 级:新手上路
帖 子:197
专家分:0
注 册:2007-7-4
收藏
得分:0 

如何做一个分页程序?

这在ASP中确实容易实现,但需要技巧,看看下面的分页代码和说明:
<anguage="vbscript"
dim conn
dim connstr
dim totalPut
dim CurrentPage
dim TotalPages
dim i,j
dim sql
dim rs
on error resume next
connstr="DBQ="+server.mappath("book.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
set rs=server.createobject("adodb.recordset")
' 打开数据库
const MaxPerPage=18
' 定义每页文章显示数
if not isempty(request("page")) then
currentPage=cint(request("page"))
else
currentPage=1
end if
sql="select * from learning order by articleid desc"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "<p align='center'> 噢,还没有文章呢,正在添加中…</p>"
else
totalPut=rs.recordcount
' 数据库中文章数totalput
if currentpage<1 then
currentpage=1
end if
' 统计总页数currentpage
if (currentpage-1)*MaxPerPage>totalput then
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut \ MaxPerPage
else
currentpage= totalPut \ MaxPerPage + 1
end if
end if
if currentPage=1 then
showpage totalput,MaxPerPage,"index.asp"
showContent
showpage totalput,MaxPerPage,"index.asp"
else
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
showpage totalput,MaxPerPage,"index.asp"
showContent
showpage totalput,MaxPerPage,"index.asp"
else
currentPage=1
showpage totalput,MaxPerPage,"index.asp"
showContent
showpage totalput,MaxPerPage,"index.asp"
end if
end if
rs.close
end if
set rs=nothing
conn.close
set conn=nothing
sub showContent
dim i
i=0
do while not rs.eof
>
<a href="openarticle.asp?id=<=rs("articleid")>"><=rs("title")></a>[点击:<=rs("hits")>]<br>
' 选择显示数据库内容
<
i=i+1
if i>=MaxPerPage then exit do
' 当显示记录大于maxperpage时结束这页
rs.movenext
loop
end sub
function showpage(totalnumber,maxperpage,filename)
' 求出当每页18篇文章时总共的页数
dim n
if totalnumber mod maxperpage=0 then
n= totalnumber \ maxperpage
else
n= totalnumber \ maxperpage+1
end if
response.write "<form method=Post action="&filename&">"
response.write "<p align='center'><font color='#000080'>>>分页</font> "
if CurrentPage<2 then
' 显示页数链接的条件
response.write "<font color='#000080'>首页 上一页</font> "
else
response.write "<a href="&filename&"?page=1&>首页</a> "
response.write "<a href="&filename&"?page="&CurrentPage-1&">上一页</a> "
end if
if n-currentpage<1 then
response.write "<font color='#000080'>下一页 尾页</font>"
else
response.write "<a href="&filename&"?page="&(CurrentPage+1)
response.write ">下一页</a> <a href="&filename&"?page="&n&">尾页</a>"
end ifc
response.write "<font color='#000080'>页次;</font><font color=red>"&CurrentPage&"</font><font color='#000080'>/"&n&"页</font>"
response.write "<font color='#000080'>共<b>"&totalnumber&"</b>篇文章 <b>"&maxperpage&"</b>篇文章/页
</font>"
response.write " <font color='#000080'>转到:</font><input type='text' name='page' size=4 maxlength=10
class=smallInput value="Currentpage&">"
response.write "<input class=buttonface type='submit' value='转到' name='cndok'></span></p></form>"
end function
>


学习ASP中.....难啊......
2007-07-09 14:51
hiddkiller
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-7-9
收藏
得分:0 

主要是SQL 语句


2007-07-09 17:13
hiddkiller
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-7-9
收藏
得分:0 
select top 每页显示的记录数 * from .......

2007-07-09 17:15
hiddkiller
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-7-9
收藏
得分:0 

从这里应该想到点什么了吧
select top 10 * from XXX where xxx in(select top (表达式) * from XXX order by xxx desc ) 其中表达式这里为(函数传进来的每页显示的 记录数 和当前要显示的页)


2007-07-09 17:19
hiddkiller
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-7-9
收藏
得分:0 
select top (表达式) * from XXX order by xxx desc 也许这句的order by xxx desc 可能语法上有点问题 我也是凭记忆写出来的 呵呵!

2007-07-09 17:21
hiddkiller
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-7-9
收藏
得分:0 

(表达式) (每页显示的记录数 * (和当前要显示的页-1))


2007-07-09 17:23
hiddkiller
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2007-7-9
收藏
得分:0 
说一个实例吧
表 stu 每页显示 10条 显示第5页 以字段 id 来查询

select top 10 * from stu where id not in(select top (10*(5-1)) * from stu order by id desc)

这样我们就顺序显示出这些数据不就行了?

2007-07-09 17:29
mjb115889
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-6-11
收藏
得分:0 
呵呵`  有点懂了
2007-07-09 19:59
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 

数据读取原理是一样的,个人认为分页其实是一个筛选数据的过程。
里面有两个关键算法
上一页记录数=(当前页-1)*每页的记录数
总也数=总纪录数/每页纪录数

2007-07-10 10:47
快速回复:ASP分页的原理是什么?
数据加载中...
 
   



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

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