紧急求助 pagesize分页 如何每一页只显示15条记录,而不是一页显示全部

chanzermin 2009-03-25 09:06:18
ASP,我用pagesize做分页,上一页、下一页、首页、尾页这些都是对的,但是有个问题,每页将所有的记录都显示,而不是按我设置的pagesize(15)大小显示条数,我google了,别人是第一次显示全部,但我是每次都这样,希望各为能帮忙解决下,谢谢。

list.asp 设计分页代码
<!--'#include file="top.asp"-->
<!--#include file="page.asp"-->
<%
if not isempty(Request.QueryString("id")) then
dim listDb,mypage
set mypage=new pageobj
set listDb = new DB
listDb.openDB
set btmrs=listDb.execRS("select * from linkfile where file_type='友情链接' order by file_id",1,2)
if Request.QueryString("type")="article" then
set rsType = listDb.execRS("SELECT * FROM articletype WHERE category_id="&Request.QueryString("id"),1,2)
if rsType("category_type")=1 then
father=rsType("category_text")
set rsSontype = listDb.execRS("SELECT * FROM articletype WHERE category_pid="&Request.QueryString("id"),1,2)
'如果为二级的栏目,取得父节点,并取得所有子节点
'如果为一级的栏目,取得所有子级别栏目
if not rsSontype.eof then
current=rsSontype("category_text")'标记当前位置
currentid=rsSontype("category_id")
else
currentid=rsType("category_id")
end if
set rs=listDb.execRS("select * from article where typeid2="¤tid&" order by id desc",1,2)
if not rs.eof then
mypage.pageInit rs,15
end if

elseif rsType("category_type")=2 then
current=rsType("category_text") '标记当前位置
currentid=rsType("category_id") '标记当前位置
set rsType = listDb.execRS("SELECT * FROM articletype WHERE category_id="&rsType("category_pid"),1,2)
if not rsType.eof then
father=rsType("category_text")
end if
set rsSontype = listDb.execRS("SELECT * FROM articletype WHERE category_pid="&rsType("category_id"),1,2)
set rs=listDb.execRS("select * from article where typeid2="¤tid&" order by id desc",1,2)
if not rs.eof then
mypage.pageInit rs,15
end if
end if

end if


end if
%>

page.asp 代码:
<%
class pageobj
dim rs
dim ipage
Private Sub Class_Initialize
set rs=server.createobject("adodb.recordset")
end sub
'页面参数初始化
public sub pageInit(myrs,psize)
set rs=myrs
rs.pagesize=psize
if isempty(request.QueryString("page")) then
ipage=0
else
ipage=clng(request.QueryString("page"))
end if
if ipage<=0 then
ipage=1
end if
if ipage>rs.pagecount then
ipage=rs.pagecount
end if
rs.absolutepage=ipage
end sub
'开始分页
public sub page(myurl)
dim newurl1,newurl2,newurl3,newurl4
'得到请求页号
if Instr(myurl,"?")<>0 then
newurl1=myurl&"&page=1"
newurl2=myurl&"&page="&cstr(ipage-1)
newurl3=myurl&"&page="&cstr(ipage+1)
newurl4=myurl&"&page="&cstr(rs.pagecount)
else
newurl1=myurl&"?page=1"
newurl2=myurl&"?page="&cstr(ipage-1)
newurl3=myurl&"?page="&cstr(ipage+1)
newurl4=myurl&"?page="&cstr(rs.pagecount)
end if
%>
<%
if ipage>1 then
%>
<a href="<%=newurl1%>" style="color:#000000; font-weight: bold;">第一页</a>
 
<a href="<%=newurl2%>" style="color:#000000; font-weight: bold;">上一页 </a>
<%
end if
%>
<%
if ipage<rs.pagecount then
%>
 
<a href="<%=newurl3%>" style="color:#000000; font-weight: bold;">下一页 </a>
 
<a href="<%=newurl4%>" style="color:#000000; font-weight: bold;">最后一页</a>
<%
end if
%>
<%
end sub
%>
<%
'得到总页数
public function getPagecount()
getPagecount=rs.pagecount
end function

'得到当前页号
public function getCurrentpage()
getCurrentpage=rs.absolutepage
end function

'得到总文章数
public function getRecordcount()
getRecordcount=rs.recordcount
end function
'得到单页尺寸
public function getPagesize()
getPagesize=rs.pagesize
end function
%>
<%
end class
%>
...全文
1010 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
努力的老孙 2011-11-17
  • 打赏
  • 举报
回复
我也是同样的问题,第1页就显示全部,好像pagesize不起作用
jim8590251 2009-03-25
  • 打赏
  • 举报
回复
借LZ宝地,推广下我前段时间写的ASP分页函数

'Date:2008-12-28
'使用方法
'Set Rsc = Server.CreateObject("ADODB.Recordset")
'Sqlc = "select id,pro_name,pro_pic from rec_pro order by id desc"
'Rsc.open sqlc,conn,3,3
'if not Rsc.eof then
'Dim i
'i=0
'分页前加上以下2句话
'Rsc.absolutepage = pageset(Rsc,18)
'pag = Rsc.absolutepage
'do while not Rsc.eof and i<Rsc.pagesize
'i = i+1
'''''在这里写循环内容'''
'Rsc.movenext
'loop
'以下是显示上页,下页,跳转页等内容,可以用<tr><td>或者table包含他
'注意,Rs.close Set Rs = Nothing必须要写在以下函数的后面,否则调用会出错
'下下函数是要不要跳转到指定锚点,选其一,要跳到指定锚点就用第一个,函数的最后个参数是你设置锚点的名字,不用跳转到锚点就用第2个,最后个参数要留空,否则出错
'call page(Rsc,pag,"index.asp","maopage")'跳转到锚点的分页调用
'call page(Rsc,pag,"index.asp","")'不跳转到锚点的分页调用


Dim pag,allpages

pag=Request("pages")
if pag="" or isnumeric(pag)=false then
pag=1
else
pag=Abs(pag)
end if
'参数注释:
'Rs--数据集
'pagesize---每页显示条数
function pageset(Rs,pagesize)

Rs.pagesize=pagesize
pages=Rs.pagecount
Records=Rs.recordcount
currentpage=Cint(pag)
if currentpage="" or currentpage<1 then Currentpage=1
If currentpage>pages Then currentpage=pages
currentpage=CInt(currentpage)
Rs.absolutepage=currentpage
pageset = Rs.absolutepage
end function
'参数注释:
'Rs--数据集
'pag ----当前页
'site---- 地址
'mep ---铆点名,可选,不设要留空""
function page(Rs,pag,site,mep)
'response.write "总条数"&Rs.recordcount&"<br />"
'response.write "当前页"&pag&"<br />"
'response.write "每页显示"&Rs.pagesize&"<br/>"
'response.write "地址为"&site&"<br />"
'response.write "最后页"&(Rs.recordcount\Rs.pagesize)+1
if Rs.Recordcount<>Rs.pagesize then
if Rs.Recordcount mod Rs.pagesize =0 then
allpages=(Rs.recordcount\Rs.pagesize)
else
allpages=(Rs.recordcount\Rs.pagesize)+1
end if
else
allpages=1
end if
if instr(site,"?")<>0 then
myand="&"
else
myand="?"
end if
if mep<>"" then
mymep = mep
end if

if pag*Rs.pagesize<Rs.recordcount then
nt=pag*Rs.pagesize
else
nt=Rs.recordcount
end if
pageft= "显示<b>"&(pag-1)*Rs.pagesize+1&"</b>-<b>"&nt&"</b>条记录,共<font color='red'>"&Rs.recordcount&"</font>条记录 "
if pag=1 then
pageft=pageft& "首页 前页 "
else
if mep<>"" then
pageft=pageft& "<a href='"&site&myand&"pages=1#"&mymep&"'>首页</a> <a href='"&site&myand&"pages="&pag-1&"#"&mymep&"'>前页</a> "
else
pageft=pageft& "<a href='"&site&myand&"pages=1'>首页</a> <a href='"&site&myand&"pages="&pag-1&"'>前页</a> "
end if
end if

'if pag=(Rs.recordcount\Rs.pagesize)+1 then

if pag=allpages then
pageft=pageft& "后页 尾页"
else
if mep<>"" then
pageft=pageft& "<a href='"&site&myand&"pages="&pag+1&"#"&mymep&"'>后页</a> "
pageft=pageft& "<a href='"&site&myand&"pages="&(Rs.recordcount\Rs.pagesize)+1&"#"&mymep&"'>尾页</a>"
else
pageft=pageft& "<a href='"&site&myand&"pages="&pag+1&"'>后页</a> "
pageft=pageft& "<a href='"&site&myand&"pages="&(Rs.recordcount\Rs.pagesize)+1&"'>尾页</a>"
end if
end if
if mep<>"" then
pageft=pageft& "到第 <select name='topage' id='topage' size='1' onchange="&chr(34)&"window.location='"&site&myand&"pages='+this.value+'#"&mymep&"';"&chr(34)&">"
else
pageft=pageft& "到第 <select name='topage' id='topage' size='1' onchange="&chr(34)&"window.location='"&site&myand&"pages='+this.value;"&chr(34)&">"
end if

for i=1 to allpages
if i=pag then
pageft=pageft& "<option value='"&i&"' selected>"&i&"</option>"
else
pageft=pageft& "<option value='"&i&"'>"&i&"</option>"
end if

next

pageft=pageft& "</select>页,共"&allpages&"页"
response.write pageft
end function
chanzermin 2009-03-25
  • 打赏
  • 举报
回复
谢谢 binfanny,这个我看了一晚上,就是代码看不出问题,但是就显示就有问题,
全部记录都显示了。
never exists 2009-03-25
  • 打赏
  • 举报
回复
好像木有发现问题
Rs.pagesize=listnum
page=Request("page")
if(page-Rs.pagecount)>0 then
page=Rs.pagecount
elseif page = "" or page < 1 then
page = 1
end if
Rs.absolutepage=page
就这样的

28,409

社区成员

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

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