91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

PHP 分頁類 高洛峰 細說PHP

發布時間:2020-07-26 06:00:13 來源:網絡 閱讀:644 作者:津沙港灣 欄目:web開發

分頁類

<?php 
     //分頁類
    class Page{
            private $total;          //總記錄數
            private $nums;        //每頁顯示的條數
            private $pages;       //總頁數
            private $cpage;      //當前頁
            private $url;           //當前url
            public  function __construct($total,$nums){
                        $this->total      =     $total;
                        $this->nums     =     $nums;
                        $this->pages    =      $this->getPages();
                        $this->url         =      $this->setUrl();
                        //獲取當前頁
                        $this->cpage   =    !empty($_GET['page']) ? intval($_GET['page']):1;
                        $this->cpage   =    $this->cpage>0 ?$this->cpage:1;
                        $this->cpage   =    $this->cpage>$this->pages?$this->pages:$this->cpage;
            }
            
            private function setUrl(){
                        $url    =   $_SERVER['REQUEST_URI'];
                        if(strstr($url, "?")){
                            $arr = parse_url($url);
                            if(isset($arr['query'])){
                                parse_str($arr['query'],$output);
                            }
                            //刪除url中重復的page=n的字符串
                            unset($output['page']);
                            $url = $arr['path']."?".http_build_query($output);
                        }else{
                            $url .="?";
                        }
                        return $url;
            }
            //獲取頁數
            private function getPages(){
                        return  ceil($this->total/$this->nums);// 向上取整法
            }
            
            //首頁
            private function first(){
                        //如果當前頁是第一頁 則不顯示這些
                        if($this->cpage>1){
                            $pre    =   $this->cpage-1;
                            return '<a href="'.$this->url.'&page=1">首頁</a>&nbsp;&nbsp;<a href="'.$this->url.'&page='.$pre.'">上一頁</a>';
                        }else{
                            return '';
                        }                       
            }
            
            //列表
            private function flist(){
                        $list       =   "";
                        $num    =   4;
                        //當前頁之前的設置
                        for($i=$num;$i >=1;$i--){
                            $page   =   $this->cpage-$i;
                            if($page >1){
                                $list      .=  '&nbsp;<a href="'.$this->url.'&page='.$page.'">'.$page.'</a>&nbsp;';
                            }
                        }
                        //當前頁的設置
                        if($this->pages>1){
                            $list   .='&nbsp;'.$this->cpage.'&nbsp;';
                        }
                        //當前頁之后的設置
                        for($i=1;$i <=$num;$i++){
                            $page   =   $this->cpage+$i;
                            if($page <= $this->pages){
                                $list      .=  '&nbsp;<a href="'.$this->url.'&page='.$page.'">'.$page.'</a>&nbsp;';
                            }else{
                                break;
                            }                            
                        }
                        return $list;
            }
            
            //末頁
            private function last(){
                if($this->cpage < $this->pages){
                    $next    =   $this->cpage+1;
                    return '<a href="'.$this->url.'&page='.$next.'">下一頁</a>&nbsp;&nbsp;<a href="'.$this->url.'&page='.$this->pages.'">末頁</a> ';
                }else{
                    return '';
                }
                      
            }
            //開始    從多少條記錄開始
            private function start(){
                        return  ($this->cpage-1)*$this->nums+1;
            }
            //結束    到多少條記錄結束
            private function end(){
                        return  min($this->cpage*$this->nums,$this->total);
            }
            //當前顯示的條數
            private function currnum(){
                        return $this->end()-$this->start()+1;
            }
            //分頁方法
            public function fpage(){
                
                        $arr =  func_get_args();
                        
                        $fpage ="";
                        $pages[0]="&nbsp;共{$this->total}條記錄&nbsp;";
                        $pages[1]="&nbsp;本頁顯示".$this->currnum()."條記錄&nbsp;";
                        $pages[2]="&nbsp;從".$this->start()."-".$this->end()."條&nbsp;";
                        $pages[3]="&nbsp;{$this->cpage}/{$this->pages}&nbsp;";
                        $pages[4]="&nbsp;".$this->first()."&nbsp;";
                        $pages[5]="&nbsp;".$this->flist()."&nbsp;";
                        $pages[6]="&nbsp;".$this->last()."&nbsp;";
                        if(count($arr)<1)
                        $arr    =   array(0,1,2,3,4,5,6);
                        foreach($arr as $n){
                                $fpage  .=  $pages[$n];
                        }
                        return $fpage;
        }
        
    }

調用分頁類

        include 'print.php';
        $page = new Page(1000,10);
       echo $page->fpage(6,4,5);


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

含山县| 深水埗区| 荣成市| 台东县| 松江区| 衡水市| 闸北区| 措美县| 日照市| 东辽县| 靖远县| 三都| 开封县| 屯留县| 海伦市| 鸡泽县| 波密县| 山东| 淮安市| 长宁县| 昭苏县| 文成县| 舞阳县| 广南县| 德格县| 剑河县| 西林县| 丹巴县| 永顺县| 长垣县| 漯河市| 九江县| 土默特左旗| 鹤庆县| 孝感市| 祁阳县| 武夷山市| 休宁县| 三江| 龙门县| 密云县|