溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

php面向?qū)ο蠓猪擃惔a

發(fā)布時(shí)間:2020-05-26 12:15:33 來源:網(wǎng)絡(luò) 閱讀:1027 作者:w0rdyyp 欄目:web開發(fā)
<?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;
}
}
向AI問一下細(xì)節(jié)

免責(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)容。

AI