请教一个分页逻辑

2025-03-24 16:46:01
推荐回答(3个)
回答1:

对于分页,其实只需要总记录数totalCount、每页显示记录数(一般是一个常量)pageRecords、当前浏览到的页数curPage就可以完成对其余分页相关的属性的计算。
totalCount:select count(*) from tableName where ...
总页数:totalCont/pageRecords,此时需要做一个判断,如果余数大于零,需要在商的结果上+1
起始记录索引:pageRecoords*(curPage-1)+1
终止记录索引:pageRecoords*curPage
注:上述的起止索引是以从1开始的算法,根据数据库实际情况进行调整。

相信有了上述几个数据,其余的功能也就是把这些数据汇总利用一下的事情了。

回答2:

<%

'PID 页面中的其它传参连接
'page 要显示的页码
'Vcount 总记录数
'Pnum 每页记录数
'className 超连接样式
public function ThePage(Pid,page,Vcount,Pnum,className)
dim show
page = int(page)
Pcount = abs(int(-abs(Vcount/Pnum)))
if page = "" or page <= 0 then page = 1
if page>Pcount then page=Pcount
StartPageNum=1
do while StartPageNum+10<=page
StartPageNum=StartPageNum+10
Loop
EndPageNum=StartPageNum+9

If EndPageNum>Pcount then EndPageNum=Pcount
show = show&""
show = show&"共"&Pcount&"页 共有"&Vcount&"记录 第"&page&"页 跳到第 [ "
if StartPageNum>1 then
show = show&"7"
end if
For go=StartPageNum to EndPageNum

if go<>page then
show = show&""&go&""
else
show = show&""&go&""
end if
show = show&" "
Next

if EndPageNum show = show&"8"
end if
show = show& "] 页"

if page<>1 then
show = show&" 首页 上一页"
end if

if Pcount-page <> 0 then
show = show& " 下一页 尾页"
end if
show=show&""
ThePage = show
end function
%>




<%

dim conn1,page
set conn1=server.CreateObject("adodb.connection")
conn1.open "driver={microsoft access driver (*.mdb)};dbq="&server.MapPath("/mdb/Article.mdb")
sub conn1_close()
set conn1=nothing
end sub

'分页参数设置
page = request.querystring("page")
if page = "" then page = 1
page = int(page)
Pnum = 15
className = "lwf"
PID = ""
'以下不变
set rs=server.CreateObject("adodb.recordset")
sql="select id,title from news"
rs.open sql,conn1,1,1

Vcount = RS.recordcount
if RS.recordcount <> 0 then
RS.absoluteposition=RS.absoluteposition+((abs(page)-1)*Pnum)
end if

'********************************
i = 1
while not RS.eof and i<=Pnum

%>


<%
rs.movenext
i = i + 1
wend
rs.close
set rs = nothing
%>



文章的ID 文章标题 文章修改 文章删除 选择
<%=rs("id")%> <%=rs("title")%> ">修改删除



<%=ThePage(Pid,page,Vcount,Pnum,className)%>




===================
上面是一个分页函数例用的例子你参考下
主要的分页逻辑就是这部分
rs.open sql,conn1,1,1

Vcount = RS.recordcount
if RS.recordcount <> 0 then
RS.absoluteposition=RS.absoluteposition+((abs(page)-1)*Pnum)
end if

回答3:

32位是实地址指的是该系统地址总线为32条,而48位是虚拟地址,2^48是虚拟地址空间,实际的内存大小是2^32即4GB存储空间。还有啊 2^36/4kb=2^24 不是1M吧 是16M吧。再好好看看书 详细看看多级也表那部分 然后问问老师……