Combined with the thinkPHP page in his class page

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

<?php 
// +----------------------------------------------------------------------
// | Reference ThinkPHP page class changed
// +----------------------------------------------------------------------
// | There are two kinds of style: 1, face to face, always in the middle of the page. 2, when the page order on both sides, automatic page (the default). 
// +----------------------------------------------------------------------
// | Author: zbseoag <>
// +----------------------------------------------------------------------
// $Id: page.class.php  2013-05-26 00:08:49

 session_start(); //Due to record the user is forward, or backward, so the session enabled

class Page{

    public $page; //The current page
    public $nextPage; //On one page
    public $prevPage; //The next page
    public $pageMax; //The maximum page
    public $startPage; //Strip at least
    public $endPage;  // Strip check code
    public $style; //Style: $style = mid
    public $parameter;//Take parameters page Jump
    public $varPage;//The default page variable
    public $url = null;  //The specified URL address
    
    protected $config = array(
        'header'=>'Records','prev'=> 'previous','next'=>' next ',' home ','first'=>'last'=>' end',
        'theme' => '%records% %header% %page%/The%pageMax% page%firstPage%%prevPage%%linkPage%%nextPage%%lastPage%'
    );
     
    /**
     +----------------------------------------------------------
     * Frame made function
     +----------------------------------------------------------
     * @param  $Records total number of records
     * @param  $The pageSize page shows the number of records
     * @param  $Parameter pageVal page Jump
     * @param  $Parameter additional parameters
     +----------------------------------------------------------
    */
     
    function __construct($records, $pageSize, $pageVal = 'p', $parameter = null){
         
        $this->records = $records;
        $this->pageMax = ceil($records/$pageSize);
        $this->page= max(intval($_GET[$pageVal]), 1); //A minimum of 1
        $this->page = min($this->page, $this->pageMax); //The maximum page
        $this->nextPage = $this->page + 1;
        $this->prevPage = $this->page - 1;
        $this->varPage = $pageVal; //The default page variable name
        $this->parameter = $parameter; //Additional URL parameters
    }
     
    /**
     +----------------------------------------------------------
     * Set the style
     +----------------------------------------------------------
     * @param  $The built-in name parameter name
     * @param  $Value the given parameter values
     +----------------------------------------------------------
     */
    function setConfig($name, $value){
        if(isset($this->config[$name])){
            $this->config[$name] = $value;
        }
    }
     
    /**
     +----------------------------------------------------------
     * Paging display output
     +----------------------------------------------------------
     * @param  $Length strip length
     +----------------------------------------------------------
     * @param  $Hide is to hide, the next page, such as: the first page, a page is hidden
     +----------------------------------------------------------
     */
    function show($length, $hide = false){

        if(0 == $this->records) return '';
        empty($this->url)? $this->url = $_SERVER['REQUEST_URI'] : null;
        $url = $this->url.(strpos($this->url,'?')?'':'?').$this->parameter;
        $parse = parse_url($url);
         
        if(isset($parse['query'])){
            parse_str($parse['query'],$params);
            unset($params[$this->varPage]);
            $url = $parse['path'].'?'.http_build_query($params);
        }

        if('mid' == $this->style){ //The current page is
            if($length % 2 != 0 ){
                $midder = ceil($length / 2);
                $big_repair = $midder - 1 ;//When the above method to a rounded, is here for the reduction of 1, whereas for 1
            }else{
                $big_repair = $midder = $length / 2;
            }
            $sml_repair = $midder- 1;  //This is a small patch
            $this->startPage = ($this->page  + $midder) > $this->pageMax ? $this->pageMax  - $length : $this->page - $sml_repair;
            $this->endPage = ($this->page <$midder)? $length : $this->page + $big_repair;
        }else{ //The last page turning
            $this->startPage = ($this->page >= $length)? $_SESSION['startPage'] : 1;
            $this->endPage  = $this->startPage + $length - 1;
             
            $this->lastPage =  isset($_SESSION['lastPage'])? $_SESSION['lastPage'] : 1; //The last page
            $_SESSION['lastPage'] = $this->page;  //Save the current page.
             
            if($this->lastPage <$this->page){ //After the page
                if($this->page >= $this->endPage){
                    $this->startPage = $_SESSION['startPage'] = $this->page;
                    $this->endPage = $this->startPage + $length -1;
                }
            }elseif($this->lastPage == $this->page){//Switching
                if($this->page == $this->endPage){
                    $this->startPage = $_SESSION['startPage'] = $this->page;
                    $this->endPage = $this->startPage + $length -1;
                }else{
                    $this->startPage = $_SESSION['startPage'] = $this->page - $length + 1;
                    $this->endPage = $this->startPage + $length -1;
                }
            }else{//Front page
                if($this->page == $this->startPage ){
                    $this->startPage = $_SESSION['startPage'] = $this->page - $length + 1;
                    $this->endPage = $this->startPage + $length -1;
                }
            }
            //echo 'Start page:'. $this->startPage.'<br/>';
            //echo 'The last page:'. $this->lastPage.'<br/>';
        }
        //To make a correction
        $this->startPage = min($this->pageMax - $length + 1, $this->startPage); //The maximum
        $this->startPage = max($this->startPage, 1);//The minimum for the first page (the first maximum, and minimum)
         
        $this->endPage = $this->startPage + $length -1;
        $this->endPage = min($this->pageMax, $this->endPage); //The maximum page
         
        $_SESSION['startPage'] = $this->startPage; //After the amendment, to save
         
        //echo 'Start page:'. $this->startPage.'<br/>';
        //echo 'The last page:'. $this->lastPage.'<br/>';
         
        if($this->page <= 1){//If is the home page
            $firstPage = '<span>'.$this->config['first'].'</span>';
            $prevPage = '<span>'.$this->config['prev'].'</span>';
        }else{
            $firstPage = "<span><a href='$url&$this->varPage=1'>".$this->config['first'].'</a>';
            $prevPage = "<span><a href='$url&$this->varPage=$this->prevPage'>".$this->config['prev'].'</a>';
        }
        
        if($this->page >= $this->pageMax){ //If you are the last page
            $nextPage = '<span>'.$this->config['next'].'</span>';
            $lastPage = '<span>'.$this->config['last'].'</span>';
        }else{
            $lastPage = "<a href='$url&$this->varPage=$this->pageMax'>".$this->config['last'].'</a>';
            $nextPage = "<a href='$url&$this->varPage=$this->nextPage'>".$this->config['next'].'</a>';
        }
        
        if($hide){ //If it is a hidden pattern
            ($this->nextPage >= $this->pageMax)? $nextPage = '' : null;
            ($this->prevPage <1)? $prevPage = '' : null;
        }

        for($i = $this->startPage; $i <= $this->endPage; $i++){
            if ($this->page == $i)
                $linkPage .= "<a class='current' href='$url&$this->varPage=$i'>$i</a>";
            else
                $linkPage .= "<a href='$url&$this->varPage=$i'>$i</a>";
        }
        $search = array('%records%','%header%','%page%','%pageMax%','%firstPage%','%prevPage%','%linkPage%','%nextPage%','%lastPage%');
        $replace = array($this->records,$this->config['header'],$this->page,$this->pageMax,$firstPage,$prevPage,$linkPage,$nextPage,$lastPage);
        $pageStr = str_replace($search, $replace, $this->config['theme']);

        return $pageStr;
    }
     
}
$page = new Page(340, 10);
$theme = '%records% %header% %page%/The%pageMax% page%firstPage%%prevPage%%linkPage%%nextPage%%lastPage%';
$page->setConfig('theme',$theme); //You can modify the style, for example: when the last page is not, can remove the%lastPage%, or change the position sequence
$page->setConfig('last','The last page'); //Can customize the text:'header'='records','prev'=' ''next'=' on a page, the next page 'home','first'=','last'=' crystal'
$page->url = 'http://localhost/test.php';
echo $page->show(10);

?>
 <style>
a,span{ margin:2px 5px;}
.current{ color:red;}
</style>



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Edwin at October 23, 2013 - 11:32 PM