asp+mysql 海量LIMIT分页代码

程序代码 程序代码

<!--#include file="conn.asp"-->
<%
dim totalPut
dim CurrentPage
dim TotalPages
dim i,j

const MaxPerPage = 10   '定义每一页的记录条数

'获取当前页面
if not isempty(request("page")) then
    currentPage = cint(request("page"))
else
    currentPage = 1
end if

'获取记录总数和总页数
Set Rs = Conn.execute("select count(*) from unionuser ")
totalPut = cint(rs(0))
if totalPut mod maxperpage = 0 then    '假如有20条记录,TotalPages = 2 页,假如有25条记录,TotalPages = 2 + 1
  TotalPages = totalPut \ maxperpage
else
  TotalPages = totalPut \ maxperpage + 1
end if

Set rs= Server.CreateObject ("ADODB.RecordSet")

rs.open "select * from unionuser order by id desc LIMIT "&(currentPage-1)*MaxPerPage&","&MaxPerPage,conn,1,3

'--------------------------------------------------------------------------------------调用内容和分页函数

call showcontent
call showpage

'--------------------------------------------------------------------------------------内容

sub showcontent
response.write "<table width=""100%""  border=""1"" align=""center"">"
response.write "  <tr>"
response.write "    <td>id</td>"
response.write "    <td>userid</td>"
response.write "    <td>userpassword</td>"
response.write "    <td>nickname</td>"
response.write "    <td>gender</td>"
response.write "    </tr>"
dim i
i=0
do while not rs.eof

'-----------------------------------------------------------------------------  
'显示内容
'-----------------------------------------------------------------------------
id = rs("id")
    userid = rs("userid")
    userpassword = rs("userpassword")
    nickname = rs("nickname")
    gender = rs("gender")
    
  %>
  <tr>
    <td><%=id%></td>
    <td><%=userid%></td>
    <td><%=userpassword%></td>
    <td><%=nickname%></td>
    <td><%=gender%></td>
    </tr><%
i=i+1
if i >= MaxPerPage then exit do
rs.movenext
loop
%></td>
  </tr>
</table><%
end sub

'------------------------------------------------------------------------------------------分页
sub showpage

response.Write("<table><TR><TD>")
response.write "<form name=myform method=get action="""">"

if CurrentPage<2 then
' 显示页数链接的条件
response.write "<font color='#999999'>首页 上一页</font> "
else
response.write "<a href=?page=1>首页</a> "
response.write "<a href=?page="&CurrentPage-1&">上一页</a> "
end if
if TotalPages-currentpage<1 then
response.write "<font color='#999999'>下一页 尾页</font> "
else
response.write "<a href=?page="&(CurrentPage+1)
response.write ">下一页</a> <a href=?page="&TotalPages&">尾页</a> "
end if
response.write "<font color='#000000'>页次</font> <font color=red>"&CurrentPage&"</font><font color='#000000'>/"&TotalPages&"页</font> "
response.write "<font color='#000000'>共<b>"&totalPut&"</b>个 <b>"&maxperpage&"</b>个/页</font>"
response.write " <font color='#000000'>转到:</span>"

response.Write("<select name='page' onchange='{this.document.myform.submit();return true;}'>")
for i=1 to TotalPages

if i=currentPage then
response.Write("<option selected value="&i&">")
else
response.Write("<option value="&i&">")
end if
response.Write("第"&i&"页</option>")
next
response.Write("</td></tr></table>")
response.Write("</select></form>")
end sub
%>



文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.