This article has shared the specific code of the php pagination class for your reference. The specific content is as follows
<?php /** file: Perfect page page */ class Page { private $total; //Total records in the data table private $listRows; //The number of rows displayed per page private $limit; // SQL statement uses limit clause to limit the number of records to obtain private $uri; //Automatically obtain the request address of the url private $pageNum; //Total page count private $page; //Current page private $config = array( 'head' => "Record", 'prev' => "Previous Page", 'next' => "Next Page", 'first'=> "front page", 'last' => "Last Page" ); //Show content in the pagination information, you can set it by yourself through the set() method private $listNum = 10; //The number of pages displayed in the default page list /** Constructing method, you can set the properties of the paging class @param int $total Calculate the total number of records for the page @param int $listRows Optional, sets the number of records to be displayed on each page, the default is 25 @param mixed $query optional, to pass parameters to the target page, it can be an array or query string format @param bool $ord optional, the default value is true, the page starts from the first page, and false is the last page */ public function __construct($total, $listRows=25, $query="", $ord=true){ $this->total = $total; $this->listRows = $listRows; $this->uri = $this->getUri($query); $this->pageNum = ceil($this->total / $this->listRows); /*The following judgment is used to set the current face*/ if(!empty($_GET["page"])) { $page = $_GET["page"]; }else{ if($ord) $page = 1; else $page = $this->pageNum; } if($total > 0) { if(preg_match('/\D/', $page) ){ $this->page = 1; }else{ $this->page = $page; } }else{ $this->page = 0; } $this->limit = "LIMIT ".$this->setLimit(); } /** Used to set the information to display paging, and can perform coherent operations @param string $param is the subscript of the member attribute array config @param string $value is used to set the element value corresponding to the config subscript @return object Returns the object itself $this, used for inertial operations */ function set($param, $value){ if(array_key_exists($param, $this->config)){ $this->config[$param] = $value; } return $this; } /* Instead of calling it directly, through this method, you can directly obtain the values of private member attribute limit and page outside the object */ function __get($args){ if($args == "limit" || $args == "page") return $this->$args; else return null; } /** Output paging in the specified format @param int Numbers 0-7 are used as parameters, and are used to customize the output paging structure and adjust the order of the structure. The default output of all structures @return string paging information content */ function fpage(){ $arr = func_get_args(); $html[0] = "<span class='p1'>&nbsp;common<b> {$this->total} </b>{$this->config["head"]}&nbsp;</span>"; $html[1] = " This page <b>".$this->disnum()."</b> use "; $html[2] = "&nbsp;This page from <b>{$this->start()}-{$this->end()}</b> strip&nbsp;"; $html[3] = "&nbsp;<b>{$this->page}/{$this->pageNum}</b>Page&nbsp;"; $html[4] = $this->firstprev(); $html[5] = $this->pageList(); $html[6] = $this->nextlast(); $html[7] = $this->goPage(); $fpage = '<div style="font:12px \'\5B8B\4F53\',san-serif;">'; if(count($arr) < 1) $arr = array(0, 1,2,3,4,5,6,7); for($i = 0; $i < count($arr); $i++) $fpage .= $html[$arr[$i]]; $fpage .= '</div>'; return $fpage; } /* Private method used inside the object, */ private function setLimit(){ if($this->page > 0) return ($this->page-1)*$this->listRows.", {$this->listRows}"; else return 0; } /* Private method used inside the object to automatically get the current URL accessed */ private function getUri($query){ $request_uri = $_SERVER["REQUEST_URI"]; $url = strstr($request_uri,'?') ? $request_uri : $request_uri.'?'; if(is_array($query)) $url .= http_build_query($query); else if($query != "") $url .= "&".trim($query, "?&"); $arr = parse_url($url); if(isset($arr["query"])){ parse_str($arr["query"], $arrs); unset($arrs["page"]); $url = $arr["path"].'?'.http_build_query($arrs); } if(strstr($url, '?')) { if(substr($url, -1)!='?') $url = $url.'&'; }else{ $url = $url.'?'; } return $url; } /* Private method used inside the object to get the number of records starting from the current page */ private function start(){ if($this->total == 0) return 0; else return ($this->page-1) * $this->listRows+1; } /* Private method used inside the object to get the number of records at the end of the current page */ private function end(){ return min($this->page * $this->listRows, $this->total); } /* Private method used inside the object to obtain operation information of the previous page and home page */ private function firstprev(){ if($this->page > 1) { $str = "&nbsp;<a href='{$this->uri}page=1'>{$this->config["first"]}</a>&nbsp;"; $str .= "<a href='{$this->uri}page=".($this->page-1)."'>{$this->config["prev"]}</a>&nbsp;"; return $str; } } /* Private method used inside the object to obtain page list information */ private function pageList(){ $linkPage = "&nbsp;<b>"; $inum = floor($this->listNum/2); /* List in front of the current page */ for($i = $inum; $i >= 1; $i--){ $page = $this->page-$i; if($page >= 1) $linkPage .= "<a href='{$this->uri}page={$page}'>{$page}</a>&nbsp;"; } /*The current page information */ if($this->pageNum > 1) $linkPage .= "<span style='padding:1px 2px;background:#BBB;color:white'>{$this->page}</span>&nbsp;"; /* List after the current page */ for($i=1; $i <= $inum; $i++){ $page = $this->page+$i; if($page <= $this->pageNum) $linkPage .= "<a href='{$this->uri}page={$page}'>{$page}</a>&nbsp;"; else break; } $linkPage .= '</b>'; return $linkPage; } /* Private method used inside the object to obtain operation information for the next page and the last page */ private function nextlast(){ if($this->page != $this->pageNum) { $str = "&nbsp;<a href='{$this->uri}page=".($this->page+1)."'>{$this->config["next"]}</a>&nbsp;"; $str .= "&nbsp;<a href='{$this->uri}page=".($this->pageNum)."'>{$this->config["last"]}</a>&nbsp;"; return $str; } } /* Private method used inside the object to display and process form jump page */ private function goPage(){ if($this->pageNum > 1) { return '&nbsp;<input style="width:20px;height:17px !important;height:18px;border:1px solid #CCCCCC;" type="text" onkeydown="javascript:if(==13){var page=(>'.$this->pageNum.')?'.$this->pageNum.':;location=\''.$this->uri.'page=\'+page+\'\'}" value="'.$this->page.'"><input style="cursor:pointer;width:25px;height:18px;border:1px solid #CCCCCC;" type="button" value="GO" onclick="javascript:var page=(>'.$this->pageNum.')?'.$this->pageNum.':;location=\''.$this->uri.'page=\'+page+\'\'">&nbsp;'; } } /* A private method used inside the object to obtain the number of records displayed on this page */ private function disnum(){ if($this->total > 0){ return $this->end()-$this->start()+1; }else{ return 0; } } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.