Encapsulate paging class
Create the page.class.php file to encapsulate the paging class:
##The specific code is as follows:
<?php /** * Created by PhpStorm. * User: Administrator * Date: 2018/3/5 0005 * Time: 下午 5:08 */ class Page{ private $total; //總記錄數(shù) private $pagesize;//每頁(yè)顯示的條數(shù) private $current; //當(dāng)前頁(yè) private $pagenum; //總的頁(yè)數(shù) public function __construct($total,$pagesize,$current) { $this->total=$total; $this->pagesize=$pagesize; $this->current=$current; $this->pagenum=ceil($this->total/$this->pagesize); } //獲取SQL中的limit條件 public function getLimit(){ //計(jì)算limit條件 $lim=($this->current-1)*$this->pagesize; //每頁(yè)顯示開(kāi)始的記錄數(shù) return $lim.','.$this->pagesize; } //獲得url參數(shù),用于在生成分頁(yè)鏈接時(shí)保存原有的GET參數(shù) private function getUrlParams(){ //去掉page參數(shù)并重新生成GET參數(shù)字符串 $params=$_GET; unset($params['page']); return http_build_query($params); } //獲取分頁(yè)鏈接 public function showPage(){ //如果少于1頁(yè)則不顯示分頁(yè)導(dǎo)航 if($this->pagenum<=1){ return ''; } //獲取原來(lái)的GET參數(shù) $url=$this->getUrlParams(); //拼接URL參數(shù) $url=$url?"?$url&page=":"?page="; //拼接"首頁(yè)" $first='<a href="'.$url.'1">[首頁(yè)]</a>'; //拼接上一頁(yè) $prev=($this->current==1)?'[上一頁(yè)]':'<a href="'.$url.($this->current-1).'">[上一頁(yè)]</a>'; //拼接下一頁(yè) $next=($this->current==$this->pagenum)?'[下一頁(yè)]':'<a href="'.$url.($this->current+1).'">[下一頁(yè)]</a>'; //拼接尾頁(yè) $last='<a href="'.$url.$this->pagenum.'">[尾頁(yè)]</a>'; //組合最終樣式 return "當(dāng)前為{$this->current}/{$this->pagenum} {$first} {$prev} {$next} {$last}"; } }1, you need to know what basic attributes are required for paging private $total; //The total number of records (obtained by querying the database)
private $pagesize;//The number of items displayed on each page (according to your own Need to be set)
private $current; //The current page (the default is the first page, each time you click the next page, it will add 1)
private $pagenum; //The total number of pages (through the total number of records/ The number of items displayed on each page is rounded up or calculated by (total number of records - 1/number of items displayed on each page) 1) to get