php mysql 分组 分页_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("没有这一行数据");

}

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值