最强的php分页类支持thinkphp框架

时间:2012-01-01 01:03 作者:php 点击:
最强的php分页类支持thinkphp框架!整个类代码给出并说明!

  

最强的php分页类支持thinkphp框架!整个类代码给出并说明

 

  1. <?php  
  2. /*  
  3.  * 原创代码请保留  
  4.  * php资源 http://www.phpzy.com   
  5.  */ 
  6. class Page{  
  7.     // 起始行数  
  8.     public $firstRow    ;  
  9.     // 列表每页显示行数  
  10.     public $listRows    ;  
  11.     // 分页总页面数  
  12.     protected $totalPages  ;  
  13.     // 总行数  
  14.     protected $totalRows  ;  
  15.     // 当前页数  
  16.     protected $nowPage    ;  
  17.     // 分页栏每页显示的页数  
  18.     protected $rollPage   ;  
  19.     // 分页显示定制  
  20.     protected $c  ;  
  21.     /**  
  22.      +----------------------------------------------------------  
  23.      * 架构函数  
  24.      +----------------------------------------------------------  
  25.      * @access public  
  26.      +----------------------------------------------------------  
  27.      * @param array $totalRows  总的记录数  
  28.      * @param array $listRows  每页显示记录数  
  29.      +----------------------------------------------------------  
  30.      */ 
  31.     public function __construct($totalRows,$listRows) {  
  32.         $this->totalRows = $totalRows;  
  33.         $this->listRows = !emptyempty($listRows)?$listRows:C('PAGE_LISTROWS');  
  34.         $this->totalPages = ceil($this->totalRows/$this->listRows);     //总页数  
  35.         $this->nowPage  = !emptyempty($_GET['p'])?(int)$_GET['p']:1;  
  36.         if(!emptyempty($this->totalPages) && $this->nowPage>$this->totalPages) {  
  37.             $this->nowPage = $this->totalPages;  
  38.         }  
  39.         $this->firstRow = $this->listRows*($this->nowPage-1);  
  40.     }  
  41.  
  42.       
  43.     public function setC($name,$value) {  
  44.         $this->c[$name]    =   $value;  
  45.     }      
  46.     /**  
  47.      +----------------------------------------------------------  
  48.      * 分页显示输出  
  49.      +----------------------------------------------------------  
  50.      * @access public  
  51.      +----------------------------------------------------------  
  52.      */      
  53.       
  54.     /**  
  55.      * multi($mpurl路径,$num总记录, $perpage每页多少条记录, $curpage页码p,  $maxpages = 0最大页码, $page = 10(123456789), $simple = FALSE开启上下页)  
  56.      */      
  57.     function multi($mpurl,$num=100, $perpage=10, $curpage=1,  $maxpages = 0, $page = 10, $simple = FALSE)  
  58.     {  
  59.         if($this->totalRows)$num=$this->totalRows;  
  60.         if($this->listRows)$perpage=$this->listRows;      
  61.         if($this->nowPage)$curpage$this->nowPage;  
  62.         if($this->c['page'])$page$this->c['page'];  
  63.       
  64.         $multipage = '';  
  65.         $realpages = 1;  
  66.         if($num > $perpage)  
  67.         {  
  68.             $offset = 2;  
  69.             $realpages = @ceil($num / $perpage);  
  70.             $pages = $maxpages && $maxpages < $realpages ? $maxpages : $realpages;  
  71.             if($page > $pages)  
  72.             {  
  73.                 $from = 1;  
  74.                 $to = $pages;  
  75.             } else 
  76.             {  
  77.                 $from = $curpage - $offset;  
  78.                 $to = $from + $page - 1;  
  79.                 if($from < 1)  
  80.                 {  
  81.                     $to = $curpage + 1 - $from;  
  82.                     $from = 1;  
  83.                     if($to - $from < $page)  
  84.                     {  
  85.                         $to = $page;  
  86.                     }  
  87.                 } elseif($to > $pages)  
  88.                 {  
  89.                     $from = $pages - $page + 1;  
  90.                     $to = $pages;  
  91.                 }  
  92.             }  
  93.             $html='';  
  94.             if($this->c['html']) $html=$this->c['html'];  
  95.             $d = explode("###"$this->c['dangqianye']);  
  96.             $b = explode("###"$this->c['bianhao']);  
  97.             if($this->c['shouye']){ $sy = explode("###"$this->c['shouye']);$multipage .= ($curpage - $offset > 1 && $pages > $page ? $sy['0'].$mpurl.'1'.$sy['1'].$html : '');}  
  98.             if($this->c['shangyiye']){ $s = explode("###"$this->c['shangyiye']);$multipage .=($curpage > 1 && !$simple ? $s['0'].$mpurl.($curpage - 1).$s['1'].$html'');}  
  99.             for($i = $from$i <= $to$i++)  
  100.             {  
  101.                 $multipage .= $i == $curpage ? $d[0].$i.$d[1] : $b[0].'<a href="'.$mpurl.$i.$html.'">'.$i.'</a>'.$b[1];  
  102.             }  
  103.       
  104.             if($this->c['xiayiye']){ $x = explode("###"$this->c['xiayiye']); $multipage .= ($curpage < $pages && !$simple ? $x['0'].$mpurl.($curpage + 1).$x['1'].$html : '');}  
  105.             if($this->c['moye']){ $m = explode("###"$this->c['moye']); $multipage .=($to < $pages ? $m['0'].$mpurl.$pages.$m['1'].$html : '');}  
  106.         }  
  107.         return $multipage;  
  108.     }      
  109.       
  110.       
  111.  
  112. }  
  113. ?> 

 


标签(Tag):
------分隔线----------------------------
推荐内容
热点内容