PHP学会网 php培训网 PHP暑期培训 PHP寒假培训 PHP假期培训 » PHP资源共享 » 发一个分页代码
本页主题: 发一个分页代码 打印 | 加为IE收藏 | 收藏主题 | 上一主题 | 下一主题

zhangwei520

该用户目前不在线
级别: 总版主
精华: 0
发帖: 510
威望: 511 点
金钱: 1620 PYMB
贡献值: 10046 点
在线时间:0(小时)
注册时间:2006-12-20
最后登录:2008-01-03

发一个分页代码


[php]<?php

/*
翻页类
*/
if(!defined("__CLASS_NAVPAGE__"))
{

define("__CLASS_NAVPAGE__",1);

class Turnpage extends Base_Root
{
var $db_connect; //数据库连接类

var $CurrentPage; //当前页
var $PageRecNums = 20; //每页记录条数
var $PageNums = 0; //记录总页数

var $RecNums = 0; //总记录条数

var $strSQL; //sql语句
var $condition; //条件
var $strOrderby;

// ----------
// method
// ----------

/*
设置函数
$DB_site 数据库连接类
$sql sql语句
$orderby 按某数据项排列
$RecsPage 每页显示的记录条数
*/
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 .=" 首页 上一页";
else $num .=" ";

if($this->CurrentPage < $this->PageNums) $num .=" 下一页 尾页";
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 .= "第".$i."页"; else $num .= "第".$i."页"; } $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);
}
?>
[/php]
顶端 Posted: 2006-12-21 13:57 | [楼 主]
PHP学会网 php培训网 PHP暑期培训 PHP寒假培训 PHP假期培训 » PHP资源共享

时:01-09 11:02 Copyright © 2006 phpwhy.com 权
ICP05060669

曳息 -