PHP分页代码实例
[coolcode]
function query_exec($sql,$orderby=””,$PageRecNums)
{
$this->strOrderby = $orderby;
$this->strSQL = $sql;
$this->PageRecNums = $PageRecNums;
}
/*
功 能:返回符记录总条数
参 数:null
返回值:int
描 述:该函数为外部接口函数用于
显示记录总数
*/
function GetTotalRecords()
{
return $this->RecNums;
}
/*
功 能:返回总页数
参 数:null
返回值:int
描 述:该函数为外部接口函数用于
显示总页数
*/
function GetTotalPages()
{
return $this->PageNums;
}
/*
功 能:计算记录总条数
参 数:null
返回值:null
描 述:该函数内部函数不要在外部调用该函数
*/
function SetTotalRecords()
{
$this->RecNums = $this->db_connect->num_rows($this->db_connect->query($this->strSQL));
@mysql_free_result($res);
}
/*
功 能:计算总页数
参 数:null
返回值:null
描 述:该函数是内部函数不要在外部调用
*/
function SetTotalPages()
{
$this->PageNums = Ceil($this->RecNums / $this->PageRecNums);
}
//取得每页记录条数
function GetRecsPage()
{
return $this->PageRecNums;
}
//有条件查询
function Query($condition)
{
$this->condtion = $condition;
}
//功 能:显示分页的页数
//参 数:$pages界面的显示页数
function PageList($param=””)
{
$num = ” 合计”.$this->RecNums.”记录 | “;
//显示翻页
if($this->CurrentPage >1) $num .=” 首页 CurrentPage – 1).”$param\” class=\”link1\”>上一页“;
else $num .=” “;
if($this->CurrentPage < $this->PageNums) $num .=” CurrentPage + 1).”$param\” class=\”link1\”>下一页 PageNums.”$param\” class=\”link1\”>尾页“;
else $num .=” “;
$num .= ” | 当前在”.$this->CurrentPage.”/”.$this->PageNums.”页 “.$this->PageRecNums.”记录/页”;
$num .=” | 转到:
for($i = 1;$i < ($this->PageNums+1);$i++)
{
$page = $i;
if($this->CurrentPage == $i) $num .= ““;
else $num .= ““;
}
$num .=”“;
return $num;
}
function & GetRec()
{
if(!isset($_REQUEST[“page”])) $this->CurrentPage = 1;
else $this->CurrentPage = $_REQUEST[“page”];
$this->SetTotalRecords();
$this->SetTotalPages();
$start = ($this->CurrentPage – 1) * $this->PageRecNums;
$sql = $this->strSQL.” “.$this->$condition.” “.$this->strOrderby.” limit $start,$this->PageRecNums”;
return $this->db_connect->query($sql);
}
}
global $DB,$xnavpage;
$xnavpage = new Turnpage($DB);
}
?>
[/coolcode]