最新消息: 新版網站上線了!!!

php mysql實現內容分頁類

php用mysql實現分頁的原理

<?

 

/*

 

PHP控制MYSQL分頁顯示的類

 

*/

 

/* 

 

*數據庫分頁顯示的類 

 

*/ 

 

 

 

class Page_class { 

 

 

 

var $TotalPages, $CurrentPage, $NumPerPage, $QueryStr, $Result, $DBID,$Data; 

 

var $TotalRecords, $StartRecord, $EndRecord, $RowCount ; 

 

 

 

function Setup ($NumPerPage) { 

 

$this->NumPerPage = $NumPerPage; 

 

 

 

 

function InitPage ($QueryStr,$ID) { 

 

$this->QueryStr = $QueryStr; 

 

$this->DBID = $ID; 

 

$Query = "select COUNT(*) ".strstr($QueryStr,"from"); 

 

$this->Result = @mysql_query($Query,$this->DBID) or die("內部錯誤,請聯系管理員"); 

 

$this->Data = @mysql_fetch_array($this->Result); 

 

$this->TotalRecords = $this->Data[0]; 

 

if ($this->NumPerPage > $this->TotalRecords) { 

 

$this->TotalPages = 1 ; 

 

 

else $this->TotalPages = Ceil($this->TotalRecords/$this->NumPerPage) ; 

 

 

 

 

function GetPage ($CurrentPage) { 

 

if ($CurrentPage > $this->TotalPages || $CurrentPage < 1) { 

 

return("錯誤,沒有此頁"); 

 

 

else { 

 

$this->CurrentPage = $CurrentPage ; 

 

$this->StartRecord = ($this->CurrentPage - 1)*$this->NumPerPage; 

 

$this->EndRecord = $this->CurrentPage * $this->NumPerPage; 

 

$Query = $this->QueryStr." LIMIT ".$this->StartRecord.",".$this->NumPerPage; 

 

$this->Result = @mysql_query($Query,$this->DBID) or die("查詢語句出錯,請檢查語法"); 

 

$this->RowCount = @mysql_num_rows($this->Result); 

 

$this->StartRecord += 1; 

 

return($Query); 

 

 

 

 

 

function GetData ($Row) { 

 

@mysql_data_seek($this->Result,$Row) or die("沒有這一行數據"); 

 

$this->Data = @mysql_fetch_array($this->Result) or die("沒有這一行數據");

 

 

 

 

 

 

 

?>

轉載請注明:谷谷點程序 » php mysql實現內容分頁類

体彩25选5开奖号码