[PHP] php分页类 →→→→→进入此内容的聊天室

来自 , 2021-02-04, 写在 PHP, 查看 127 次.
URL http://www.code666.cn/view/4aa0e93b
  1. @charset "utf-8";
  2. *{padding:0;margin:0;}
  3. .page {
  4.     font-size: 14px;
  5.     text-align:center
  6. }
  7. .page ul{list-style-type:none;display:table;margin-left:auto;margin-right:auto}
  8. .page ul li{min-width:20px;padding:5px;margin-left:3px;border:1px solid #CCC;text-align:center;float:left;*float:none;*display:inline;*zoom:1;}
  9. .page .select{font-weight:bold;color:#000;font-size:14px;background-color:#F5F5F5;}
  10. .page li a{text-decoration:none;color:#333}
  11. .page .gray{color:#808080}
  12.  
  13. <?php
  14. class page{
  15.     public $pagesize;
  16.     public $pagecount;
  17.     public $currentpage;
  18.     public $pageurl;
  19.     public $totalpage;
  20.  
  21.     function __construct($pagesize=15,$pagecount=0,$currentpage=1,$pageurl){
  22.         $this->pagesize = $pagesize;
  23.         $this->pagecount = $pagecount;
  24.         $this->currentpage = $currentpage;
  25.         $this->pageurl = $pageurl;
  26.         $this->totalpage = ceil($this->pagecount / $this->pagesize);
  27.         }
  28.  
  29.     function showpage(){
  30.         $pagelink = "";
  31.  
  32.         $pagelink .= "<div class='page'><ul>";
  33.         //判断是否为第一页
  34.         if($this->currentpage==1){
  35.             $pagelink .= "<li class='gray'>最前页</li>";
  36.         }else{
  37.             $pagelink .= "<li><a href=\\"$this->pageurl"."p=1\\">最前页</a></li>";
  38.             }
  39.  
  40.         if($this->currentpage > 1 && $this->totalpage > 1){
  41.             $prepage = $this->currentpage -1;
  42.             $pagelink .= "<li><a href=\\"$this->pageurl"."p=".$prepage."\\">上一页</a></li>";
  43.         }else{
  44.             $pagelink .= "<li class='gray'>上一页</li>";
  45.             }
  46.  
  47.         //判断页总数
  48.         if($this->totalpage <= 11){
  49.             $frompage = 1;
  50.             $topage = $this->totalpage;
  51.         }else{
  52.             if($this->currentpage <= 6){
  53.             $frompage = 1;
  54.             $topage = 11;
  55.             }
  56.             else if($this->currentpage > 6 && $this->totalpage - 6 > $this->currentpage){
  57.             $frompage = $this->currentpage - 5;
  58.             $topage = $this->currentpage + 5;
  59.             }else{
  60.             $frompage = $this->totalpage - 11;
  61.             $topage = $this->totalpage;
  62.                 }
  63.             }
  64.  
  65.         for($i=$frompage;$i<=$topage;$i++){
  66.             if($i==$this->currentpage){
  67.                 $pagelink .= "<li class=\\"select\\">$i</li>";
  68.             }else{
  69.                 $pagelink .= "<li><a href=\\"".$this->pageurl."p=$i\\">$i</a></li>";
  70.                 }
  71.             }
  72.         //最后页面判断
  73.         if($this->currentpage < $this->totalpage){
  74.             $nextpage = $this->currentpage + 1;
  75.             $pagelink .= "<li><a href=\\"$this->pageurl"."p=".$nextpage."\\">下一页</a></li>";
  76.         }else{
  77.             $pagelink .= "<li class='gray'>下一页</li>";
  78.             }
  79.  
  80.         if($this->currentpage==$this->totalpage){
  81.             $pagelink .= "<li class='gray'>最后页</li>";
  82.         }else{
  83.             $pagelink .= "<li class='gray'><a href=\\"$this->pageurl"."p=$this->totalpage\\">最后页</a></li>";
  84.             }
  85.         $pagelink .="</ul>";
  86.         $pagelink .="<br clear=\\"left\\" />";
  87.         $pagelink .="</div>";
  88.         return $pagelink;
  89.         }
  90.  
  91.     }
  92.  
  93. ?>
  94.  
  95.  

回复 "php分页类"

这儿你可以回复上面这条便签

captcha