程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php相當簡單的分頁類

php相當簡單的分頁類

編輯:關於PHP編程

class Helper_Page{

/** 總信息數 */
var $infoCount;
/** 總頁數 */
var $pageCount;
/** 每頁顯示條數 */
var $items;
/** 當前頁碼 */
var $pageNo;
/** 查詢的起始位置 */
var $startPos;
/** 下一頁 */
var $nextPageNo;
/** 上一頁 */
var $prevPageNo;

function Helper_Page($infoCount, $items, $pageNo)
{
$this->infoCount = $infoCount;
$this->items = $items;
$this->pageNo = $pageNo;
$this->pageCount = $this->GetPageCount();
$this->AdjustPageNo();
$this->startPos = $this->GetStartPos();
}
function AdjustPageNo()
{
if($this->pageNo == '' || $this->pageNo < 1)
$this->pageNo = 1;
if ($this->pageNo > $this->pageCount)
$this->pageNo = $this->pageCount;
}
/**
* 下一頁
*/
function GoToNextPage()
{
$nextPageNo = $this->pageNo + 1;
if ($nextPageNo > $this->pageCount)
{
$this->nextPageNo = $this->pageCount;
return false;
}
$this->nextPageNo = $nextPageNo;
return true;
}
/**
* 上一頁
*/
function GotoPrevPage()
{
$prevPageNo = $this->pageNo - 1;
if ($prevPageNo < 1)
{
$this->prevPageNo = 1;
return false;
}
$this->prevPageNo = $prevPageNo;
return true;
}
function GetPageCount()
{
return ceil($this->infoCount / $this->items);
}
function GetStartPos()
{
return ($this->pageNo - 1) * $this->items;
}
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved