PHP实现分页的一个示例

 1   
 2if(!$whichpage)   
 3{   
 4$notepage=1;   
 5}   
 6else   
 7{   
 8$notepage=$whichpage;   
 9}   
10$noterecs=0;   
11$pagesize=10;   
12$bbsconn=mysql_connect("localhost","root");   
13mysql_select_db("rainwindy",$bbsconn);   
14$bbsresult=mysql_query("select * from bbs order by id desc",$bbsconn);   
15$rsnum=mysql_num_rows($bbsresult);   
16$pagecount=ceil($rsnum/$pagesize);   
17mysql_data_seek($bbsresult,($notepage-1)*10);   
1<div align="right">
2<table border="0" cellpadding="0" cellspacing="0" width="730">
3<tr>
4<td align="center" bgcolor="#C0C0C0" bordercolor="#0000FF" height="30" valign="middle" width="41">编号</td>
5<td align="center" bgcolor="#C0C0C0" bordercolor="#0000FF" height="30" valign="middle" width="100">用户名</td>
6<td align="center" bgcolor="#C0C0C0" bordercolor="#0000FF" height="30" valign="middle" width="100">发表人</td>
7<td align="center" bgcolor="#C0C0C0" bordercolor="#0000FF" height="30" valign="middle" width="311">文章标题</td>
8<td align="center" bgcolor="#C0C0C0" bordercolor="#0000FF" height="30" valign="middle" width="239">发表时间</td>
9</tr>   

while(($bbsrow=mysql_fetch_array($bbsresult)) &amp;&amp; ($noterecs&lt;=9))
{

 1<tr>
 2<td align="center" bgcolor="#FFFFCC" height="30" valign="middle" width="41">```
 3 echo $bbsrow["id"] 
 4```</td>
 5<td align="center" bgcolor="#FFFFCC" height="30" valign="middle" width="100">```
 6 echo $bbsrow["usr"] 
 7```</td>
 8<td align="center" bgcolor="#FFFFCC" height="30" valign="middle" width="100">```
 9 echo $bbsrow["name"] 
10```</td>
11<td align="center" bgcolor="#FFFFCC" height="30" valign="middle" width="311"><a ```"="" href="bbsdisp.php?whichnote=```
12 echo $bbsrow[" id"]="" target="disp">```
13 echo $bbsrow["title"] 
14```</a></td>
15<td align="center" bgcolor="#FFFFCC" height="30" valign="middle" width="239">```
16 echo $bbsrow["bbstime"] 
17```</td>
18</tr>   

$noterecs=$noterecs+1;
}

1</table>
2</div>
1<br/>
1<br/>
1<center>   

$pad=0;
for($counter=1;$counter&lt;=$pagecount;$counter++)
{
if($counter&gt;=10)
{
$pad="";
}

echo("<font color="red" size="+1"><a href="bbsbl.php?whichpage=$counter">".$pad.$counter."</a></font>  ");
}

Published At
Categories with Web编程
Tagged with
comments powered by Disqus