如何分页显示数据库查询结果
推荐于2016-10-04
展开全部
最简单的ASP分页代码
<%
set conn=server.createobject("adodb.connection")
conn.open("DRIVER=Driver do Microsoft Access (*.mdb);UID=admin;pwd=;dbq="&server.mappath("1.mdb"))
set rs=server.createobject("adodb.recordset")
sql="select * from student"
rs.open sql,conn,3
rs.pagesize=20
if request("page")<>"" then
epage=cint(request("page"))
if epage<1 then epage=1
if epage>rs.pagecount then epage=rs.pagecount
else
epage=1
end if
rs.absolutepage=epage
%>
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#0000FF" width="80%" align="center">
<tr bgcolor="#FFFFFF" align="center">
<th><%=rs(0).name%></th><th><%=rs(1).name%></th><th><%=rs(2).name%></th>
</tr>
<%
for i=0 to rs.pagesize-1
if rs.bof or rs.eof then exit for
%>
<tr bgcolor="#FFFFFF" align="center">
<td><%=rs(0).value%></td><td><%=rs(1).value%></td><td><%=rs(2).value%></td>
</tr>
<%
rs.movenext()
next
%>
</table>
<p align="center">
<a href="">首页</a>
<a href="index.asp?page=<%=epage-1%>">前一页</a>
<a href="index.asp?page=<%=epage+1%>">后一页</a>
<a href="index.asp?page=<%=rs.pagecount%>">末页</a>
</p>
<p align="center">现在是第<%=epage%>页一共有<%=rs.pagecount%>页</p>
<%
conn.close()
%>
<%
set conn=server.createobject("adodb.connection")
conn.open("DRIVER=Driver do Microsoft Access (*.mdb);UID=admin;pwd=;dbq="&server.mappath("1.mdb"))
set rs=server.createobject("adodb.recordset")
sql="select * from student"
rs.open sql,conn,3
rs.pagesize=20
if request("page")<>"" then
epage=cint(request("page"))
if epage<1 then epage=1
if epage>rs.pagecount then epage=rs.pagecount
else
epage=1
end if
rs.absolutepage=epage
%>
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#0000FF" width="80%" align="center">
<tr bgcolor="#FFFFFF" align="center">
<th><%=rs(0).name%></th><th><%=rs(1).name%></th><th><%=rs(2).name%></th>
</tr>
<%
for i=0 to rs.pagesize-1
if rs.bof or rs.eof then exit for
%>
<tr bgcolor="#FFFFFF" align="center">
<td><%=rs(0).value%></td><td><%=rs(1).value%></td><td><%=rs(2).value%></td>
</tr>
<%
rs.movenext()
next
%>
</table>
<p align="center">
<a href="">首页</a>
<a href="index.asp?page=<%=epage-1%>">前一页</a>
<a href="index.asp?page=<%=epage+1%>">后一页</a>
<a href="index.asp?page=<%=rs.pagecount%>">末页</a>
</p>
<p align="center">现在是第<%=epage%>页一共有<%=rs.pagecount%>页</p>
<%
conn.close()
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询