您好,登錄后才能下訂單哦!
<?php //自定義分頁類 class Page { public $page=1; //當(dāng)前頁 public $pageSize=5; //頁大小 public $maxPage=0; //最大頁數(shù) public $maxRows=0; //最大數(shù)據(jù)條 public $url =null; //訪問的url地址 public $params=null; //url的參數(shù)條件 public function __construct($maxRows,$pageSize=5){ $this->maxRows = $maxRows; $this->pageSize= $pageSize; //獲取當(dāng)前頁 $this->page = isset($_GET['p'])?$_GET['p']:1; $this->getMaxPage(); $this->checkPage(); //獲取和封裝url地址 $this->url = $_SERVER["PHP_SELF"]; $this->getParams(); } //獲取分頁信息 public function limit(){ return (($this->page-1)*$this->pageSize).",".$this->pageSize; } //計(jì)算分頁中的最大頁數(shù) private function getMaxPage(){ $this->maxPage = ceil($this->maxRows/$this->pageSize); } //判斷當(dāng)前頁數(shù)是否越界 private function checkPage(){ if($this->page>$this->maxPage){ $this->page = $this->maxPage; } if($this->page<1){ $this->page=1; } } //封裝url上搜索條件 private function getParams(){ foreach($_GET as $k=>$v){ if($k!="p" && !empty($v)){ $this->params.="&{$k}={$v}"; } } } //生成分頁HTML代碼 public function show(){ $str = ""; $str.= "當(dāng)前第{$this->page}/{$this->maxPage}頁 共計(jì){$this->maxRows}條 "; $str.= " <a href='{$this->url}?p=1{$this->params}'>首頁</a> "; $str.= " <a href='{$this->url}?p=".($this->page-1)."{$this->params}'>上一頁</a> "; $str.= " <a href='{$this->url}?p=".($this->page+1)."{$this->params}'>下一頁</a> "; $str.= " <a href='{$this->url}?p={$this->maxPage}{$this->params}'>末頁</a> "; return $str; } }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。