一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

一個簡單且很好用的php分頁類

復(fù)制代碼 代碼如下:
class Page {
    // 分頁欄每頁顯示的頁數(shù)
    public $rollPage = 6;
    // 頁數(shù)跳轉(zhuǎn)時要帶的參數(shù)
    public $parameter  ;
    // 默認(rèn)列表每頁顯示行數(shù)
    public $listRows = 20;
    // 起始行數(shù)
    public $firstRow ;
    // 分頁總頁面數(shù)
    protected $totalPages  ;
    // 總行數(shù)
    protected $totalRows  ;
    // 當(dāng)前頁數(shù)
    protected $nowPage    ;
    // 分頁的欄的總頁數(shù)
    protected $coolPages   ;
    // 分頁顯示定制
    protected $config  = array(
     'redirect'=>false,
     'header'=>'條記錄',
     'prev'=>'',
     'next'=>'',
     'first'=>'1',
     'last'=>'最后一頁',
     'theme'=>' <div class="part1">%upPage% %first%  %prePage%  %linkPage%  %nextPage% %downPage%</div> <div class="part2">共  %totalPage% 頁');
    // 默認(rèn)分頁變量名
    protected $varPage;

    /**
     +----------------------------------------------------------
     * 架構(gòu)函數(shù)
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @param array $totalRows  總的記錄數(shù)
     * @param array $listRows  每頁顯示記錄數(shù)
     * @param array $parameter  分頁跳轉(zhuǎn)的參數(shù)
     +----------------------------------------------------------
     */
    public function __construct($totalRows,$listRows='',$parameter='') {
        $this->totalRows = $totalRows;
        $this->parameter = $parameter;
        $this->varPage = C('VAR_PAGE') ? C('VAR_PAGE') : 'p' ;
        if(!empty($listRows)) {
            $this->listRows = intval($listRows);
        }
        $this->totalPages = ceil($this->totalRows/$this->listRows);     //總頁數(shù)
        $this->coolPages  = ceil($this->totalPages/$this->rollPage);
        //$_GET驗證
        $this->nowPage = intval($_GET[$this->varPage]);
        $this->nowPage = $this->nowPage > 0 ? $this->nowPage : 1;

        if(!empty($this->totalPages) && $this->nowPage>$this->totalPages) {
            $this->nowPage = $this->totalPages;
        }
        $this->firstRow = $this->listRows*($this->nowPage-1);
    }

    public function setConfig($name,$value) {
        if(isset($this->config[$name])) {
            $this->config[$name]    =   $value;
        }
    }

    /**
     +----------------------------------------------------------
     * 分頁顯示輸出
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     */
    public function show() {

     if(0 == $this->totalRows) return '';

     //處理參數(shù)
        $p = $this->varPage;
        $url  =  $_SERVER['REQUEST_URI'].(strpos($_SERVER['REQUEST_URI'],'?')?'':"?").$this->parameter;
        $parse = parse_url($url);
        if(isset($parse['query'])) {
            parse_str($parse['query'],$params);
            unset($params[$p]);
            $url   =  $parse['path'].'?'.http_build_query($params);
        }

        /* 分頁邏輯  */      

        //當(dāng)總數(shù)小于顯示的頁碼數(shù)
        if ($this->totalPages <= $this->rollPage) {
         $start = 1;
         $end   = $this->totalPages;
        }
        else{
         //
         if  ($this->nowPage <= $this->rollPage - 1) {
          $start = 1;
          $end   = $this->rollPage;

          $islast = true;
         } 
         else if ($this->nowPage > $this->totalPages - $this->rollPage + 1) {
          $start = $this->totalPages - ($this->rollPage - 1);
          $end   = $this->totalPages;

          $isfirst = true;
         }
         else{
          //浮動數(shù)
          $size = floor($this->rollPage / 2);

          $start = $this->nowPage - $size;
          $end   = $this->nowPage + $size;

          $isfirst = true;
          $islast = true;
         }
        }

        //上下翻頁字符串
        $upRow   = $this->nowPage - 1;
        $downRow = $this->nowPage + 1;

       
        /* 拼裝HTML */

        //< 1...     ...last >
        if ($isfirst){
         $theFirst = "<a class='firstPage' href='".$url."&".$p."=1' >".$this->config['first']."</a>";
        }
        if ($islast){
         $theEnd = "<a class='lastPage' href='".$url."&".$p."=$this->totalPages' >".$this->config['last']."</a>";
        }

        if ($upRow > 0){
         $upPage = "<a class='upPage' href='".$url."&".$p."=$upRow'>".$this->config['prev']."</a>";
        }

        if ($downRow <= $this->totalPages){
         $downPage = "<a class='downPage' href='".$url."&".$p."=$downRow'>".$this->config['next']."</a>";
        }

       if($start==3){
         $linkPage .= "<a href='".$url."&".$p."=2'>2</a>";
        }
        if($start>=4){
         $linkPage .= "<a href='".$url."&".$p."=2'>2</a> <span class='noEndClass'>...</span>";
        }
        //1 2 3 4 5
        for($i=$start;$i<=$end;$i++){
         if($i!=$this->nowPage){
          $linkPage .= " <a href='".$url."&".$p."=$i'> ".$i." </a>";
         }else{
          $linkPage .= " <span class='current'>".$i."</span>";
         }
         if($i==$end){
          if($i<$this->totalRows){
           $linkPage .= " <span class='noEndClass'>...</span>";
          }
         }
        }

        $pageStr = str_replace(
            array('%header%','%nowPage%','%totalRow%','%totalPage%','%upPage%','%first%','%prePage%','%linkPage%','%nextPage%','%downPage%','%end%'),
            array($this->config['header'],$this->nowPage,$this->totalRows,$this->totalPages,$upPage,$theFirst,$prePage,$linkPage,$nextPage,$downPage,$theEnd),$this->config['theme']);

        //顯示模式  普通false 帶跳轉(zhuǎn)ture
        if (!empty($this->config['redirect'])){
         $html = $pageStr;

        }else{
         //傳遞參數(shù)
         if($this->totalPages > 1){
          $redirect = " 到第 <form method='get' action=''><input name=".$p." type='text' class='page_text' size='3' maxlength='3' value='" . $this->nowPage ."'/> 頁 <input type='submit' class='page_btn' value='確定' />";
          if ($params){
           foreach($params as $k => $v){
            $string .= "<input type='hidden' name='" . $k . "' value='" . $v . "'/>";
           }
           $redirect = $redirect . $string . '</form></div>';
          }else{
           $redirect = $redirect . '</form></div>';
          }
         }
         //生成Html字符串
         $html = $pageStr . $redirect;      
        } 
        return $html;
    }

}

php技術(shù)一個簡單且很好用的php分頁類,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 国产激情一级毛片久久久 | 九九视频热 | 亚洲伊人激情 | 欧美色视频网 | 国产美女网站 | 在线中文字幕精品第5页 | 99在线精品视频在线观看 | 国产在线短视频 | 日本www色视频 | 91啦视频在线观看 | 加勒比日本道 | 一区一精品 | 久草五月 | 天天天色综合 | 色狠狠成人综合网 | 不卡国产00高中生在线视频 | 国产精品久久久久久久牛牛 | 精品麻豆视频 | 亚洲午夜在线观看 | 中文字幕色站 | 色多多18免费观看 | 久久综合一区二区三区 | 91热视频 | 亚洲最大的视频网站 | 91全国探花精品正在播放 | 激情综合网站 | 国产精品美女一区二区 | 国产成人精品999在线观看 | 久久久久久亚洲精品不卡 | 伊人久久成人成综合网222 | 国产成人在线播放 | 久久九九精品视频 | 黄色大片久久 | 三级网站国产 | 99精品国产福利在线观看 | 成人午夜精品 | 都市激情亚洲色图 | 在线黄视频 | 88国产精品视频一区二区三区 | 国产日韩欧美综合色视频在线 | 国产一区二区成人 |