php mysql网页分页代码
在php+mysql数据库的分页代码中比以前的asp,asp.net相对来就容易很多,因为mysql支持limit,0,N这样就可以轻松快速的获取要读取的记录,好下面来看实例
<?php function getpage($talbe, $choose, $url) { global $page, $db, $sortname; $query = $db->query("select * from $talbe $choose"); $total = $db->num_rows($query); $totalpage = ceil($total / 25); $nextpage = $page + 1; $uppage = $page - 1; if ($nextpage > $totalpage) $nextpage = $totalpage; if ($uppage < 1) $uppage = 1; $showpage = "共有<b><font color='#FF0000'>$total</font></b>条记录, 共<b><font color='#FF0000'>$totalpage</font></b>页,当前为第<b> <font color='#FF0000'>$page</font></b>页 <b><font color='#FF0000'>◇</font></b> <a href='?$url&page=$uppage&sortname=$sortname'>上一页</a> <b><font color='#FF0000'>◇</font></b> <a href='?$url&page=$nextpage&sortname=$sortname'>下一页</a> <font color='#FF0000'><b>◇"; return $showpage; } function reto($msg, $url = '') { global $comeurl; if (!$url) $url = $comeurl; return "<table width='100%' cellspacing='1' cellpadding='3' bgcolor='#CCCCCC'> <tr bgcolor='#FFFFFF'> <td> <div align='center'> <font size='+6'><b><font size='5'> <a href='$url'><font color='#993300'>$msg</font></a> </font></b></font></div> </td> </tr> </table>"; }
通过上页的代码我们可以看出php分页原创很简单,只要get[page]页面,当前页,然后再用 $page * $pagesize以开始,后以$pagesize为结束就OK了。mysql语句为$sql = "Select * from t limit $page*$pagesize,$pagesize";
本文地址:http://www.phprm.com/code/33269.html
转载随意,但请附上文章地址:-)