自己写的百度分页效果含样式

Posted on 2015-05-27 00:44  小蕊同学  阅读(151)  评论(0编辑  收藏  举报
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>分页</title>
  6. <style>
  7. .page{height:30px;padding:15px;clear:both;text-align:center;}
  8. .page a{padding:0px 10px;text-decoration:none;display:inline-block;margin-right:5px;border:solid 1px #c8c7c7;width:40px;height:35px;line-height:35px;font-size:13px;}
  9. .page a:hover,.page a.checked{text-decoration:none;border:solid 1px #0086d6;background:#0091e3;color:#fff;}
  10. .page a.pages{
  11. font-weight:800;
  12. padding:0px
  13. 10px;text-decoration:none;display:inline-block;margin-right:5px;width:40px;height:35px;line-height:35px;font-size:13px;border:none;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <?php
  19. include 'mysqli.php';
  20. $rr=$m->query('select count(*) from member');
  21. $rs=$rr->fetch_row();
  22. $recordcount=$rs[0];//共14条记录
  23. $pagesize=1;//每页2条记录
  24. $pagecount=ceil($recordcount/$pagesize);//总共有几页
  25. $currpage=isset($_GET['p']) ? $_GET['p']:1;//显示当前页
  26. $currpage=$currpage<1 ? 1 :$currpage;
  27. $currpage=$currpage>$pagecount ? $pagecount : $currpage;
  28. $start=$currpage*$pagesize-$pagesize;
  29. $r=$m->query("select id,maccount,mname from member limit $start,$pagesize");//里面用变量了所以外面要用单引号
  30. while($rs=$r->fetch_row()){
  31. echo $rs[1].'<br>';
  32. }
  33. $st = 1;
  34. $en = 10;
  35. if($currpage>=6){
  36. $st=$currpage-5;
  37. $en=$st+$en-1;
  38. }
  39. ?>
  40. <hr>
  41. <div class="page">
  42. <?php
  43. if($currpage>1){
  44. $pre=$currpage-1;
  45. if($st>1){
  46. echo "<a href='?p=1'>首页</a><a href='?p=$pre'>上一页</a>";
  47. }else{
  48. echo "<a href='?p=$pre'>上一页</a>";
  49. }
  50. }
  51. for($j=$st;$j<=$en;$j++){
  52. if($j>$pagecount){
  53. break;
  54. }
  55. if($currpage==$j){
  56. echo "<a class='pages checked'>$j</a>&nbsp;";
  57. continue;
  58. }
  59. echo "<a href='?p=$j'>$j</a>&nbsp;";
  60. } if($currpage<$pagecount){
  61. $nex=$currpage+1;
  62. if($en<$pagecount){
  63. echo "<a href='?p=$nex'>下一页</a><a href='?p=$pagecount'>尾页</a>";
  64. }else{
  65. echo "<a href='?p=$nex'>下一页</a>";
  66. }
  67. }
  68. // echo "当前页{$currpage}/共{$pagecount}页";
  69. ?>
  70. </div>
  71. </body>
  72. <html>





Copyright © 2024 小蕊同学
Powered by .NET 9.0 on Kubernetes