大神幫小弟我看下,小弟我的查詢分頁類錯哪了分頁類

來源:互聯網
上載者:User
大神幫我看下,我的查詢分頁類哪裡錯了分頁類

這是page.class.php
class DividePage{//分頁類
private $total;//要顯示的總記錄數
private $url;//請求的URL地址
private $displaypg;//每頁顯示的記錄數,預設為每頁顯示10條記錄
private $page;//當前頁碼
private $lastpg;//總頁數,即最後一頁的頁碼
private $prepg;//前一頁
private $nextpg;//後一頁
private $firstcount;//記錄條數開始的序號從0開始
private $startd;//記錄條數開始的記錄號.
private $stopd;//記錄條數結束的記錄號.

//建構函式
public function __construct($url, $total, $displaypg){
$this->url = $url;//請求的URL
$this->total = $total;//總記錄數
//if($displaypg == '')
$this->displaypg = $displaypg;//每頁顯示的記錄數
$this->initDividePage();//初始化分頁類
//echo ','.$this->displaypg;
}

//初始化分頁類
private function initDividePage(){
//分析URL
$parse_url = parse_url($this->url);//將URL解釋為有固定索引值對的數組
$url_query = $parse_url['query'];//取出URL中的查詢字串
if($url_query){//如果有查詢字串,則刪除查詢字串中當前頁的查詢欄位如:&page=$page或page=$page
ereg('(^|&)page=([0-9]*)', $url_query, $k);
$this->page = $k[2];//取得當前頁的值
$url_query = ereg_replace("(^|&)page=$this->page", '', $url_query);//刪除查詢字串中當前頁的查詢欄位如:&page=$page或page=$page
$this->url = str_replace($parse_url['query'], $url_query, $this->url);//保留其他的查詢字串,
$this->page = $this->page ? $this->page : 1;//如果查詢字串中沒有當前頁的值就設當前頁為1
if($url_query){//如果有其他查詢字串,則以&page=$page形式添加翻頁查詢字串
$this->url .= '&page';
}else{//如果沒有其他查詢字串,則以page=$page形式添加翻頁查詢字串
$this->url .= 'page';
}
}else{//如果沒有查詢字串,則在URL後添加?page=$page形式的翻頁查詢字串
$this->page = 1;
$this->url .= '?page';
}
$this->lastpg = ceil($this->total / $this->displaypg);//計算總頁數,即最後一頁的頁碼
$this->page = min($this->lastpg, $this->page);//如果當前頁大於總頁數,則當前頁為最後一頁的頁碼
$this->prepg = $this->page - 1;//上一頁為當前頁減一
$this->nextpg = $this->page + 1;//(($this->page == $this->lastpg) ? $this->lastpg : ($this->page + 1));//下一頁為當前頁加一,如果當前頁為最後一頁,則下一頁為0
$this->firstcount = ($this->page - 1) * $this->displaypg;//計算當前頁,記錄條數開始的記錄號,從0開始.
$this->startd = $this->total ? ($this->firstcount + 1) : 0;//記錄開始號從1開始
$this->stopd = min($this->firstcount + $this->displaypg, $this->total);//記錄結束號
//echo $this->displaypg;
//echo $this->nextpg.'+=+='.$this->lastpg;
}

public function getPageInfo(){//取得當前頁面的基本資料,如:顯示第 1-10 條記錄,共 23 條記錄。
return '顯示第'.$this->startd.'-'.$this->stopd.'條記錄,共'.$this->total.'條記錄。';
}

public function getCommonPageNav(){//取得通常的分頁導航,如:首頁 上一頁 下一頁 尾頁
$commonnav = '';
if($this->lastpg == 1){//如果只有一頁,則返回翻頁導航,退出,不顯示下一頁,上一頁等。。。
return $commonnav;
break;
}
$commonnav = 'url.'=1" class="compagestyle">首頁';//設定首頁導航,page=1
if($this->prepg){
$commonnav .= 'url.'='.$this->prepg.'" class="compagestyle">上一頁';
}else{
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.