高效分页 asp
‘每页的记录数
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 "<SCRIPT language=JavaScript>alert(‘参数错误!‘);"
response.write "window.close();</SCRIPT>"
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
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")&"<br>"
rs.movenext
loop
rs.close
set rs=nothing
‘‘翻页代码省略……
%>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。