楼主,主要还是玩SQL语句的使用,需要那页的几条就Top对应的
以下代码供参考:
<%
'每页的记录数
dim pagesize
pagesize= "30"
'读出总记录数,总页数,作者注
dim totalrecords,totalpages
sqlstr="select count(id) as recordsum from table1"
set rs=conn.execute(sqlstr,0,1)
totalrecords=rs("recordsum")
if int(totalrecords/pagesize)=totalrecords/pagesize then
totalpages=totalrecords/pagesize
else
totalpages=int(totalrecords/pagesize)+1
end if
rs.close
set rs=nothing
dim page
page=request("page") '获取当前要查看的页码
if isnumeric(page)=false then
response.write ""
response.end
end if
if page="" or page<1 then page=1
if page-totalpages>0 then page=totalpages
page=int(page)
if page=1 then
sql="select top "&pagesize&" id,title,time from table1 order by time desc"
else
'最主要看懂下面这句,选择的就是小于上一页最后一条记录的发布消息时间,共计取pagesize条
sql="select top "&pagesize&" id,title,time from table1 where time<(select min (time) from (select top "&pagesize*(page-1)&" time from table1 order by time desc) as t) order by time desc"
end if
set rs = server.createobject ("adodb.recordset")
rs.open sql,conn,1,1
do while not rs.eof
response.write "每条记录信息:"&rs("id")&"
"
rs.movenext
loop
rs.close
set rs=nothing
''翻页代码省略
%>
个人觉得第二种也用第一种方法写,主要的区别仅仅是sql语句的问题。
使用分页函数
'分页函数
'格式为:共有 13 条记录 第[1 2 3 4 5〕 页
function page_split(pagesize,currentpage,filename,rss,svar)
dim splitStr
if currentpage<>"" then
currentpage=cint(currentpage)
else
currentpage=1
end if
rss.pagesize=pagesize
rss.AbsolutePage=currentpage
splitStr=splitStr& "共有 "&rss.recordcount&" 条记录 "
for i=1 to rss.PageCount
if i=currentpage then
splitStr=splitStr& "["&i&"]"
else
splitStr=splitStr& "[" &"" &i &"" &"]"
end if
next
page_split=splitStr
end function
调用方式:
<%
pagesize=16 '每页显示记录数目
page=request("page")
if page="" then
page=1
else
page=cint(page)
end if
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
if not rs.eof then
page_i=page_split(pagesize,page,"news.asp",rs,"")'调用函数赋值给page_i,在后面相应的位置调用显示page_i
num=0
do while not rs.eof and num
num=num+1
rs.movenext
loop
else
end if
rs.close
set rs=nothing
%>