亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

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

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

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

札达县| 方城县| 日照市| 怀仁县| 蕲春县| 文山县| 清远市| 沂南县| 临漳县| 湄潭县| 长乐市| 兴城市| 理塘县| 呼和浩特市| 礼泉县| 舞钢市| 姚安县| 宿迁市| 潼南县| 门源| 莲花县| 阿瓦提县| 来安县| 巨野县| 都匀市| 裕民县| 剑河县| 萨嘎县| 江门市| 南昌市| 黑河市| 巴马| 江油市| 潜江市| 富阳市| 宁蒗| 西畴县| 天长市| 华阴市| 同江市| 台湾省|