导读:php mysql分页代码实例教程,感觉还不错,就分享出来给大家,适合新手学习。希望对你们有所帮助
php mysql分页代码实例教程,感觉还不错,就分享出来给大家,适合新手学习。希望对你们有所帮助
- $qh=mysql_query("select count(*) as rcnt from table where your_condition_here order by whatever");
- $data=mysql_fetch_array($qh);
- $nr=$data["rcnt"];
- if (emptyempty($offset))
- {
- $offset=0;
- }
- $result=mysql_query("select id,name,phone from table where your_condition_here order by whatever limit $offset, 20");
- while ($data=mysql_fetch_array($result))
- {
- }
- if(!$offset)
- {
- $preoffset=$offset-20;
- print "<a href="$php_self?offset=$preoffset">前一页</a> ";
- }
- $pages=ceil($nr/20);
- for ($i=1; $i <= $pages; $i++)
- {
- $newoffset=20*$i;
- print "<a href="$php_self?offset=$newoffset">$i</a> ";
- }
- if ($pages!=0 && ($newoffset/20)!=$pages)
- { //开源代码www.bcty365.com
- print "<a href="$php_self?offset=$newoffset">下一页</a> ";
- }
-