PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > PHP教程 > 正文

    php mysql分页代码实例教程

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:php mysql分页代码实例教程,感觉还不错,就分享出来给大家,适合新手学习。希望对你们有所帮助
    php mysql分页代码实例教程,感觉还不错,就分享出来给大家,适合新手学习。希望对你们有所帮助
    1. $qh=mysql_query("select count(*) as rcnt from table where your_condition_here order by whatever");  
    2. $data=mysql_fetch_array($qh);  
    3. $nr=$data["rcnt"];  
    4. //判断偏移量参数是否传递给了脚本,如果没有就使用默认值0
    5. if (emptyempty($offset)) 
    6. {  
    7. $offset=0;  
    8. //查询结果(这里是每页20条,但你自己完全可以改变它) 
    9. $result=mysql_query("select id,name,phone from table where your_condition_here order by whatever limit $offset, 20"); 
    10. //显示返回的20条记录 
    11. while ($data=mysql_fetch_array($result))  
    12. //换成你用于显示返回记录的代码
    13. //下一步,要写出到其它页面的链接 
    14. if(!$offset//如果偏移量是0,不显示前一页的链接 
    15. {  
    16. $preoffset=$offset-20;  
    17. print "<a href="$php_self?offset=$preoffset">前一页</a>&nbsp; ";  
    18. //计算总共需要的页数 
    19. $pages=ceil($nr/20); //$pages变量现在包含所需的页数
    20. for ($i=1; $i <= $pages$i++)  
    21. {  
    22. $newoffset=20*$i;  
    23. print "<a href="$php_self?offset=$newoffset">$i</a>&nbsp; ";  
    24. //检查是否是最后一页 
    25. if ($pages!=0 && ($newoffset/20)!=$pages)  
    26. //开源代码www.bcty365.com
    27. print "<a href="$php_self?offset=$newoffset">下一页</a>&nbsp; ";  
    28. }
    29.  
    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-10-1546-1.html
    相关热词搜索: php mysql分页 php分页