这个还带分页<!--
只要存成index.asp页就行,
如果存储成别的文件名,需要把页面里的index.asp都替换成相应的文件名
-->
<html>
<title>分页技术</title>
<head>
<%
   const MaxPerPage=25  '每页的记录数
   dim sql 
   dim rs
   dim totalPut   
   dim CurrentPage
   dim TotalPages
   dim i,j 
%>
</head>
<body bgcolor=#99CCFF>
<P align=center><FONT size=5 face="方正舒体"><STRONG>实例&nbsp;&nbsp;&nbsp; 
分页技术</STRONG><%
conn = "DBQ=" + server.mappath("mydb.mdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};" 
sql = "SELECT * FROM mytable"
set rs=server.createobject("adodb.recordset") 
rs.open SQL,conn,1,1
rs.MoveFirst
rs.pagesize=MaxPerPage         '把记录集分页
howmanyfields=rs.Fields.Count-1If trim(Request("Page"))<>"" then
CurrentPage= CLng(request("Page")) 
If CurrentPage> rs.PageCount then 
CurrentPage = rs.PageCount 
End If 
Else 
CurrentPage= 1 
End If if rs.eof then 
response.write "<p align='center'> ERROR!</p>" 
else 
totalPut=rs.recordcount
if CurrentPage<>1 then 
if (currentPage-1)*MaxPerPage<totalPut then 
rs.move(currentPage-1)*MaxPerPage 
dim book 
book=rs.book
end if 
end if dim n,k 
if (totalPut mod MaxPerPage)=0 then  
n= totalPut \ MaxPerPage
else  
n= totalPut \ MaxPerPage + 1  
end if%>
</FONT></P>
<P>PAGE <%=currentpage%> OF <%=n%>   共<%=rs.recordcount%> 纪录
<% k=currentPage
if k<>1 then
response.write "[<b>"+"<a href='index.asp?page=1'>首页</a></b>] "
response.write "[<b>"+"<a href='index.asp?page="+cstr(k-1)+"'>上一页</a></b>] "
else
Response.Write "[首页] [上一页]"
end if
if k<>n then
response.write "[<b>"+"<a href='index.asp?page="+cstr(k+1)+"'>下一页</a></b>] "
response.write "[<b>"+"<a href='index.asp?page="+cstr(n)+"'>尾页</a></b>] "
else
Response.Write "[下一页] [尾页]"
end if
%></P><TABLE border=1 align=center>
<tr>
<%
for i= 0 to howmanyfields%>
<TD><B><%=rs(i).name%></B> </TD>
<%
next
i=0
do while not rs.eof and i<maxperpage%>
<tr align=middle>
<%for j=0 to howmanyfields%>
<td>
&nbsp;<%=rs(j)%>&nbsp;
</td>
<%next%>
</tr>
<%
i=i+1
rs.movenext 
loop
%>
</TABLE>
<%
end if 
rs.close 
set rs=nothing 
%>
</body>
</html>

解决方案 »

  1.   

    如果是MYSQL数据库,可以利用limit语法
      

  2.   

    一个页面中用两个相似的tsql,都是select的,第一个取得有多少个记录,再定义每页显示多个记录。
    第二个select用到limit,例如select * from db1 limit 开始记录,取多少记录.
    开始记录根据一个中间的偏移值决定,你可上网查一个select 中limit的具体用法即可。
      

  3.   

    还是看你的吧,我的简单明了,呵呵。------------------------<br><html><head><title>PHP分页</title></head><body><?
    $gPageSize= 50; //每页显示的记录数$hostname = "localhost"; //mysql Server$dbuser = "root"; //用户名$dbpasswd = ""; //密码//连接数据库$id = mysql_connect($hostname,$dbuser,$dbpasswd) or die("无法连接数据库服务器!");//选择数据库$db = mysql_select_db("infodb",$id) or die("无法连接数据库!");$query = "select * from ipinfo";//执行查询语句$rresult = mysql_query($query) or die("无法执行SQL:$query");//$page变量标示当前显示的页if(!isset($page)) $page=1;if($page==0) $page=1;//得到当前查询到的纪录数 $nNumRowsif(($nNumRows= mysql_num_rows($rresult))<=0){echo "<p align=center>没有纪录";exit;};//得到最大页码数MaxPage$MaxPage = (int)ceil($nNumRows/$gPageSize);if((int)$page > $MaxPage)$page=$maxPage;?><table align="center" width="80%" border=0> <tr><td><? echo "<font size=2>第
    $page 页,共 $MaxPage 页</font>";?></td><td></td></tr></table><table align="center" width="80%" border="1" cellspacing="0" cellpadding="4" bordercolorlight="#CC9966" bgcolor="#00F2EE" bordercolordark="#FFFFFF" class="LZH"><tr bgcolor="#F7F2ff" style="font-size:14.8px;font-weight:bold"><?//显示表格头for($iCnt = 0; $iCnt < mysql_num_fields($rresult); $iCnt++){echo "<td>".mysql_field_name($rresult,$iCnt)."</td>" ;}?></tr><?//根据偏移量($page - 1)*$gPageSize,运用mysql_data_seek函数得到要显示的页面if( mysql_data_seek($rresult,($page-1)*$gPageSize) ){$i=0;//循环显示当前纪录集for($i;$i<$gPageSize;$i++){echo "<tr style=\"font-size:12px\">";//得到当前纪录,填充到数组$arr;$arr= mysql_fetch_row($rresult);if($arr){//循环显示当前纪录的所有字段值for($nOffSet = 0;$nOffSet < count($arr);$nOffSet++){echo "<td>".$arr[$nOffSet]."</td>";}}echo "</tr>";}}?></table><br><hr size=1 width=80%><div align=center style="font-size:12px"><?//首页和上一页的链接if( $nNumRows>1 && $page>1){$prevPage=$page-1;echo " <a href=$PHP_SELF?page=1>首页</a> ";echo " <a href=$PHP_SELF?page=$prevPage >上一页</a> ";}//下一页和末页的链接if( $page>=1 && $page<$MaxPage){$nextPage= $page+1;echo " <a href=$PHP_SELF?page=$nextPage >下一页</a> ";echo " <a href=$PHP_SELF?page=$MaxPage >末页</a> ";}?></div></body></html>