首页 > 编程开发 > Php > 正文  
PHP&MYSQL数据库分页显示的类
出自:www.eatsun.com 2002年08月21日 22:00
<?
/*
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("没有这一行数据");

}
}

?>
】【http://www.trainlinux.com】【Close
『相关资料』
PHP的十个高级技巧(上) (2002-08-21 22:00)
PHP的十个高级技巧(中) (2002-08-21 21:59)
PHP的十个高级技巧(下) (2002-08-20 21:59)
php编写大型网站问题集 (2002-08-20 21:59)
Home 

诚恩Linux培训工作室