救急! 给一个查询页加上分页功能 在线等
access数据库 数据库文件名111.mdb 表名work 里面有两个字段account和tel
这页是查询显示,我想加入分页功能,如“当前第X页 共X页 共X条记录 上一页 下一页”
下面是asp页面的代码
弄了半天 一直没弄好 请救救急 在我的这页上加上分页功能 谢谢!
<html>
<head>
<title> </title>
</head>
<body>
<TABLE>
<TR> <TD>
<%
set conn=server.createobject( "adodb.connection ")
connstr= "driver={microsoft access driver (*.mdb)};dbq= "&server.mappath( "111.mdb ")
conn.open connstr
set rs=server.createobject( "adodb.recordset ")
sql= "select * from work order by id desc "
rs.open sql,conn,1,1
if rs.eof and rs.bof then
%> 目前没有任何记录 <%else%> <%do while not rs.eof%>
<%=rs( "account ")%> || <%=rs( "tel ")%>
<br>
<%
rs.movenext
loop
end if
rs.close
%>
</TD> </TR> </table>
</body>
</html>
[解决办法]
<!--#include file= "conn.asp "-->
<html>
<head>
<meta http-equiv= "Content-Language " content= "zh-cn ">
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<meta name= "GENERATOR " content= "Microsoft FrontPage 5.0 ">
<meta name= "ProgId " content= "FrontPage.Editor.Document ">
<link rel= "stylesheet " type= "text/css " href= "css/css.css ">
<title> xxxxx </title>
</head>
<body leftmargin= "0 " topmargin= "0 ">
<%
MaxPerPage=20
dim totalPut
dim CurrentPage
dim TotalPages
dim i,j
dim typename
typename= " "
if not isempty(request( "page ")) then
currentPage=cint(request( "page "))
else
currentPage=1
end if
dim sql
dim rs
dim rstype
dim typesql
dim typeid,typename1
if not isEmpty(request( "typeid ")) then
typeid=request( "typeid ")
else
typeid=0
end if
%>
<table border= "0 " width= "100% " cellspacing= "0 " cellpadding= "0 ">
<tr>
<td width= "100% "> </td>
</tr>
</table>
<%
sql= "select * from work order by id desc "
Set rs= Server.CreateObject( "ADODB.Recordset ")
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write " <p align= 'center '> 还 没 有 记 录 </p> "
else
totalPut=rs.recordcount
totalPut=rs.recordcount
if currentpage <1 then
currentpage=1
end if
if (currentpage-1)*MaxPerPage> totalput then
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut \ MaxPerPage
else
currentpage= totalPut \ MaxPerPage + 1
end if
end if
if currentPage=1 then
showpage totalput,MaxPerPage, "test.asp "
showContent
showpage totalput,MaxPerPage, "test.asp "
else
if (currentPage-1)*MaxPerPage <totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
showpage totalput,MaxPerPage, "test.asp "
showContent
showpage totalput,MaxPerPage, "test.asp "
else
currentPage=1
showpage totalput,MaxPerPage, "test.asp "
showContent
showpage totalput,MaxPerPage, "test.asp "
end if
end if
end if
sub showContent
dim i
i=0
%>
<div align= "center ">
<center>
<table border= "0 " cellspacing= "1 " width= "779 " bordercolorlight= "#000000 " bordercolordark= "#FFFFFF " cellpadding= "2 " height= "33 " style= "border-collapse: collapse " bordercolor= "#111111 ">
<tr bgcolor= "#CCCCCC ">
<td width= "301 " align= "center " bgcolor= "#CCCCCC " height= "7 "> <b> account </b> </td>
<td width= "467 " height= "20 " align= "center " bgcolor= "#CCCCCC "> <b> tel </b> </td>
</tr>
<%do while not rs.eof%>
<tr>
<td height= "4 " width= "301 " bgcolor= "#FFFFFF "> <p align= "center "> <%=rs( "account ")%> </td>
<td height= "4 " align= "center " bgcolor= "#FFFFFF "> <%=rs( "tel ")%> </td>
</tr>
<% i=i+1
if i> =MaxPerPage then exit do
rs.movenext
loop
%>
</table>
</center>
</div>
<%
end sub
function showpage(totalnumber,maxperpage,filename)
dim n
if totalnumber mod maxperpage=0 then
n= totalnumber \ maxperpage
else
n= totalnumber \ maxperpage+1
end if
response.write " <p align= " "center " "> <form method=Post action= "&filename& "?typeid= "&typeid& "> "
if CurrentPage <2 then
response.write " <font color= '#000080 '> 首页 上一页 </font> "
else
response.write " <a href= "&filename& "?page=1&typeid= "&typeid& "> 首页 </a> "
response.write " <a href= "&filename& "?page= "&CurrentPage-1& "&typeid= "&typeid& "> 上一页 </a> "
end if
if n-currentpage <1 then
response.write " <font color= '#000080 '> 下一页 尾页 </font> "
else
response.write " <a href= "&filename& "?page= "&(CurrentPage+1)& "&typeid= "&typeid& "> "
response.write "下一页 </a> <a href= "&filename& "?page= "&n& "&typeid= "&typeid& "> 尾页 </a> "
end if
response.write " <font color= '#000080 '> 页次: </font> <strong> <font color=red> "&CurrentPage& " </font> <font color= '#000080 '> / "&n& " </strong> 页 </font> "
response.write " <font color= '#000080 '> 共 <b> "&totalnumber& " </b> 条 <b> "&maxperpage& " </b> 条/页 </font> "
response.write " <font color= '#000080 '> 转到: </font> <input type= 'text ' name= 'page ' size=4 maxlength=10 class=smallInput value= "¤tpage& "> "
response.write " <input class=buttonface type= 'submit ' value= 'Goto ' name= 'cndok '> </span> </p> </form> </p> "
end function
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
</body>
</html>
[解决办法]
<%
id = request( "id ")
Set rs = Server.CreateObject( "ADODB.RecordSet ")
sql= "sql= "select * from work order by id desc " "
rs.open sql,conn,1,3
rs.pagesize=10
page=request( "page ")
if page <> " " then
pageno=cint(page)
if pageno <1 then
pageno=1
end if
else
pageno=1
end if
if rs.recordcount> 0 then
rs.absolutepage=pageno
end if
rowcount=rs.pagesize
%>
</tr>
<%
If Not rs.eof then
do while not rs.eof and rowcount> 0
%>
<%=rs( "account ")%> || <%=rs( "tel ")%>
<br>
<%
rowcount=rowcount-1
rs.movenext
loop
else
%>
<tr>
<td bgcolor= "#f0f0f0 " align= "center " colspan= "8 "> 暂无内容!! </td>
</tr>
<%
End If
%>
<table width= "100% " border= "0 " cellpadding= "0 " cellspacing= "0 ">
<tr class= "tdbg ">
<td height= "25 " bgcolor= "#F0F0F0 " align= "right ">
<table width= "100% " border= "0 " align= "center " cellpadding= "2 " cellspacing= "1 ">
<tr>
<td height= "25 " bgcolor= "#F0F0F0 " colspan= "5 " align= "right ">
现在记录: <font color= "red "> <%=rs.recordcount%> </font>
<%if pageno <> 1 then%>
<a href= "aa.asp?page=1 "> < < </a>
<a href= "aa.asp?page= <%=pageno-1%> "> < </a>
<%End If %>
<%
n=1
TPages = rs.pagecount
do While ( n <6 And n <=TPages)
%>
<a href= "aa.asp?page= <%=n%> "> <%=n%> </a>
<%
n=n+1
loop
%>
<%if pageno <> TPages And pageno <> 0 then%>
<a href= "aa.asp?page= <%=pageno+1%> "> > </a>
<a href= "aa.asp?pagen= <%=TPages%> "> > > </a>
<%End If %>
</td>
</tr>
</table>
</td>
</tr>
</table>