当前位置:Gxlcms > PHP教程 > 急好看实用的PHP+JS分页!效果类似百度

急好看实用的PHP+JS分页!效果类似百度

时间:2021-07-01 10:21:17 帮助过:3人阅读

急!求一个好看实用的PHP+JS分页!效果类似百度
急!求一个好看实用的PHP+JS分页!效果类似百度!

效果如下:

1 2 3 4 5 6 7 8 9 10 下一页 共有?页

当不是第一页的时候,显示如下:

上一页 1 2 3 4 5 6 7 8 9 10 下一页 共有 ?页

其中,用“另一种颜色标记出当前显示的是哪一页”

该分页代码能跟MYSQL数据库连接使用,实现像百度的分页效果!

小弟是新手,都吧知道如何下手,请各位大哥帮帮忙!谢谢!

------解决方案--------------------
PHP code
  1. function _setPage($baseUrl, $total, $start, $limit, $parm="")
  2. {
  3. if($total != 0) $pages = $total/$limit; else $pages = 0;
  4. if(empty($start)) $start=0;
  5. if(empty($limit)) $limit=20;
  6. if($start>$total)$start=$total-$limit;
  7. if($start<0) $start=0;
  8. if($limit<0) $limit=0;
  9. if($limit>100) $limit=100;
  10. //$start = $start - $top;
  11. $showpage = 10;
  12. $currentpage=$start/$limit;
  13. if($currentpage<5){
  14. $pageno=0;
  15. $i=0;
  16. } else{
  17. if($currentpage+10 > $total/$limit ){
  18. $pageno=$currentpage -5;
  19. }else{
  20. $pageno=$currentpage - 5;
  21. }
  22. $i=$pageno*$limit;
  23. }
  24. if($total==0) $currentpage = -1;
  25. $strPage = "总[" . ($currentpage + 1) . "/" . ceil($pages) . "]页 ";
  26. $page=0;
  27. $strPage .= "";
  28. if($start/$limit > $showpage)
  29. {
  30. $tmp = ($pageno - 1)* $limit;
  31. $strPage.= "<<";
  32. }
  33. while($i < $total)
  34. {
  35. if($start/$limit ==$pageno)
  36. {
  37. $strPage .= "<font color="red">". ($pageno + 1) ." </font>";
  38. }
  39. else
  40. {
  41. $strPage .= "".($pageno + 1)." ";
  42. }
  43. $pageno++;
  44. $page++;
  45. $i+=$limit;
  46. if($page > $showpage)
  47. {
  48. $strPage.= ">>";
  49. break;
  50. }
  51. }
  52. if($start>0){
  53. $strPage .= " 首页 ";
  54. }else{
  55. $strPage .= " 首页 ";
  56. }
  57. if($start>0){
  58. $strPage .= " 上一页 ";
  59. }
  60. if($start+$limit< $total){
  61. $strPage .= " 下一页 ";
  62. }
  63. if($start+$limit< $total){
  64. $strPage .= " 尾页 ";
  65. }else{
  66. $strPage .= " 尾页 ";
  67. }
  68. return $strPage;
  69. }
  70. <br><font color="#e78608">------解决方案--------------------</font><br>为什么要JS的?
  71. <br><font color="#e78608">------解决方案--------------------</font><br>$baseUrl为页面基本的url,比如说index.php?m=table&a=list<br>$total为你要分页的记录的总数,用来计算有多少页的.<br>$start为当前页开始的记录条数.<br>$limit为每页显示的条数,这个可以定为常量.<br>$parm为额外的参数,比如说你在$baseUrl的基础上又添加了一个search='news'的话,可以在这里添加,以便追加到url里.
  72. <br><font color="#e78608">------解决方案--------------------</font><br>学习。

人气教程排行