Write two versions, or better back, just calculate the key data, return the array, HTML code exception splicing
<?php/** * page Categories * @author timo * @version 2016-12-11 08:15 */class paginate{ //Current Page private $page; //Records total entries private $entry _total; //how many records are displayed per page private $page _size; // Total number of pure values Li, that is, the length of the page bar (excluding the top and bottom pages) private $page _li_count; //Total Pages private $page _count; private $result; private $active //The URL must be at the end? or & private $url; /** * * @param unknown $url Jump link Address * @param unknown $entry _tTotal entries for otal records * @param number $page _size number of records per page * @param number $page _li_count The page bar displays the number of li (excluding the first and last pages), which is the length of the page bar */ public Function __construct ($entry _total, $page _size = 5, $page _li_count = 1) { //initialization of member variables, parameters also need to be carefully filtered $this- >entry_total = (int) $entry _total; $this->page_ size = (int) $page _size; $this->page_count = ceil ($entry _total/$page _size); // The length of the page bar takes a user-submitted page bar length and a smaller value in the total number of pages $this->page_li_count = $page _li_count > $this->PAGE_COUNT&NBSP;? $this->page_count : $page _li_count; } /** * Set the current page and active status * @param unknown $page Legal parameter: First end 1234 */ public function setpage ($page) { if ($page == ' end ') { $this->active = ' End '; $this->page = $this->getpagecount (); }elseif ($page >0 && $page <= $this- >page_count) { $this->active = $page; $this->page = $page; }else{ //first or passing illegal values will be set to the homepage $this->active = ' first '; $this->page = 1; } } /** * * @param unknown $url //is required at the end of this URL? or & */ public function seturl ($url) { $this->url = $url } //Current page public function getpage () {&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp; return $this->page; } //Total number of pages public function getpagecount () { return $this->page_count; } //Total number of records Public function getentrycount () { return $this- >entry_total; } /** * to calculate the information needed for the page bar of the current page * @return return array, including splicing paging key information */ public function create () { //Home $first _page= "First"; //calculates the page number, the minimum is 1 $pre _page = ($this->page-1) <=1 ? 1 : $this->page-1; //calculate next page number , Max page_count $next _page = ($this->page+1) >=$ this->page_count ? $this->page_count : $this->page+1; //End $end _page= "End"; $nums _page = []; This judgment repeats with the judgment in the initialization variable, but ... Safety Point if ($this->page_count >= $this Page_li_count) { //Middle Li for the first few, A $mid _li = $this before even taking the middle bias- >page_li_count%2==0 ? $this->page_li_count/2 : (($this->page_li_count-1)/2) +1; //Ideally, the number of Li should be in the back of the $mid _li $right _li_num = $this->page_li_count - $mid _li; //Ideally, $mid the number of Li should be in front of _li $left _li_num = $mid _li-1; //Calculate the rightmost page number if ($this->page <= $left _li_num) { // If the number of Li on the left side of the current page is not large enough to center, the right-most page number equals the right-most Li numbering $right _li_page = $this->page_li_count; }else { $ right_li_page = ($this->page_count-$this->page) >= $right _li_num ? $ this->page+ $right _li_num : $this->page_count; } for ($i = 0; $i < $this->page_li_count ; $i + +) { //look at may be a bit around, the paper counted on the figure, known to the right Li's page number, The total number of Li, current Li's number is $i+1, calculate the current Li corresponding page number $n = $right _li_page-$this->page_li_count+ $i +1; $nums _page[] = $n; } } //the stitching together $this->result[' First '] = $first _page; $this->result[' End '] = $end _page; $this->result[' pre '] = $pre _page; $this->result[' Next '] = $next _page; $this->result[' nums '] = $nums _page; $this->result[' active '] = $this->active; return $this->result; } public function gethtml () { //to perfect ........ $url = isset ($this->url) ? $this->url : '? '; $first _class = $this->result[' active '] == ' first ' ? ' active ' : '; $end _class = $this->result[' active '] == ' end ' ? ' active ' : '; $pre _class = $this- >result[' active '] == ' pre ' ? ' active ' : '; $next _class = $this->result[' active '] == ' next ' ? ' active ' : '; $first _page_html = < <
This article is from the "woodcutter" blog, make sure to keep this source http://woodcutter.blog.51cto.com/9079117/1881779
PHP Shredding-Pagination class