分页处理
2006-04-28 08:29
134 查看
<?php
class Page{
private $sysInfo;
/*
* 存放程序关联信息
*
* @var array
* @access private
*/
private $data;
/*
* 存放数据库数据
*
* @var array
* @access private
*/
private $sql;
/*
* 数据库对象实例化
*
* @var DBPDO
* @access private
*/
public function __construct( $key , $table , $where="" , $records=10 , $maxPage=10 )
{
/*
* 创建对象
*
* @param string $key
* @param string $table
* @param string $where
* @param int $records
* @param int $maxPage
* @access public
*/
settype( $_GET[ $key ] , "integer" );
$this->sql = new DBPDO( );
$this->sysInfo['key'] = $key;
$this->sysInfo['page'] = max( $_GET[ $key ]-1 , 0 );
$this->sysInfo['table'] = $table;
$this->sysInfo['where'] = $where;
$this->sysInfo['records'] = $records;
$this->sysInfo['maxPage'] = $maxPage;
}
private function query( )
{
/*
* 获取记录相关信息
*
* @access private
*/
$query = "select count(*) from ".$this->sysInfo['table'];
$query .= $this->sysInfo['where'] ? " where ".$this->sysInfo['where'] : "";
if( !$this->sql->query( $query ) )
{
return( false );
}
$result = $this->sql->GetResult( );
$this->sysInfo['resTotal'] = $result[0];
$this->sysInfo['record'] = $this->sysInfo['page']*$this->sysInfo['records'];
$query = "select * from ".$this->sysInfo['table'];
$query .= $this->sysInfo['where'] ? " where ".$this->sysInfo['where'] : "";
$query .= " limit ".$this->sysInfo['record'].",".$this->sysInfo['records'];
if( !$this->sql->query( $query ) )
{
return( false );
}
$this->data = $this->sql->GetResults( );
$this->sysInfo['queryTotal'] = count( $this->data );
$this->sysInfo['pageTotal'] = ceil( $this->sysInfo['resTotal'] / $this->sysInfo['records'] );
$currentPage = $this->sysInfo['page'] % $this->sysInfo['maxPage'];
$start = min( $this->sysInfo['pageTotal'] , floor( $this->sysInfo['page'] / $this->sysInfo['maxPage'] )*$this->sysInfo['maxPage'] );
$this->sysInfo['currentPageStart'] = max( $start , 0 );
$this->sysInfo['currentPageEnd'] = min( $this->sysInfo['currentPageStart']+$this->sysInfo['maxPage'] , $this->sysInfo['pageTotal'] );
$this->sysInfo['next'] = min( $this->sysInfo['pageTotal'] , $this->sysInfo['page']+1 );
$prev = min( $this->sysInfo['pageTotal'] , $this->sysInfo['page'] );
$this->sysInfo['prev'] = max( 0 , $prev-1 );
return( true );
}
public function __get( $property )
{
/*
* 获取对象的关联信息
*
* @param string $property
* @access public
*/
switch( strtolower( $property ) )
{
case "key":
return( $this->sysInfo['key'] );
break;
case "value":
return( $this->sysInfo['value'] );
break;
case "table":
return( $this->sysInfo['table'] );
break;
case "where":
return( $this->sysInfo['where'] );
break;
case "recordtotal":
return( $this->sysInfo['recordTotal'] );
break;
case "maxpage":
return( $this->sysInfo['maxPage'] );
break;
case "restotal":
return( $this->sysInfo['resTotal'] );
break;
case "pagetotal":
return( $this->sysInfo['pageTotal'] );
break;
case "currenttotal":
return( $this->sysInfo['currentPageTotal'] );
break;
case "start":
return( $this->sysInfo['currentPageStart'] );
break;
case "end":
return( $this->sysInfo['currentPageEnd'] );
break;
case "next":
return( $this->sysInfo['next'] );
break;
case "prev":
return( $this->sysInfo['prev'] );
break;
case "sysinfo":
return( $this->sysInfo );
break;
default:
return( false );
}
}
public function getRecords( )
{
/*
* 获取数据库记录信息
*
* @access public
*/
if( !$this->data )
{
if( !self::query( ) )
{
return( false );
}
}
return( $this->data );
}
public function showError( )
{
return( $this->error->pross( ) );
}
public function __destruct( )
{
/*
* 释放对象占用的资源
*
* @access public
*/
$this->sql = NULL;
$this->sysInfo = NULL;
$this->data = NULL;
}
}
?>
class Page{
private $sysInfo;
/*
* 存放程序关联信息
*
* @var array
* @access private
*/
private $data;
/*
* 存放数据库数据
*
* @var array
* @access private
*/
private $sql;
/*
* 数据库对象实例化
*
* @var DBPDO
* @access private
*/
public function __construct( $key , $table , $where="" , $records=10 , $maxPage=10 )
{
/*
* 创建对象
*
* @param string $key
* @param string $table
* @param string $where
* @param int $records
* @param int $maxPage
* @access public
*/
settype( $_GET[ $key ] , "integer" );
$this->sql = new DBPDO( );
$this->sysInfo['key'] = $key;
$this->sysInfo['page'] = max( $_GET[ $key ]-1 , 0 );
$this->sysInfo['table'] = $table;
$this->sysInfo['where'] = $where;
$this->sysInfo['records'] = $records;
$this->sysInfo['maxPage'] = $maxPage;
}
private function query( )
{
/*
* 获取记录相关信息
*
* @access private
*/
$query = "select count(*) from ".$this->sysInfo['table'];
$query .= $this->sysInfo['where'] ? " where ".$this->sysInfo['where'] : "";
if( !$this->sql->query( $query ) )
{
return( false );
}
$result = $this->sql->GetResult( );
$this->sysInfo['resTotal'] = $result[0];
$this->sysInfo['record'] = $this->sysInfo['page']*$this->sysInfo['records'];
$query = "select * from ".$this->sysInfo['table'];
$query .= $this->sysInfo['where'] ? " where ".$this->sysInfo['where'] : "";
$query .= " limit ".$this->sysInfo['record'].",".$this->sysInfo['records'];
if( !$this->sql->query( $query ) )
{
return( false );
}
$this->data = $this->sql->GetResults( );
$this->sysInfo['queryTotal'] = count( $this->data );
$this->sysInfo['pageTotal'] = ceil( $this->sysInfo['resTotal'] / $this->sysInfo['records'] );
$currentPage = $this->sysInfo['page'] % $this->sysInfo['maxPage'];
$start = min( $this->sysInfo['pageTotal'] , floor( $this->sysInfo['page'] / $this->sysInfo['maxPage'] )*$this->sysInfo['maxPage'] );
$this->sysInfo['currentPageStart'] = max( $start , 0 );
$this->sysInfo['currentPageEnd'] = min( $this->sysInfo['currentPageStart']+$this->sysInfo['maxPage'] , $this->sysInfo['pageTotal'] );
$this->sysInfo['next'] = min( $this->sysInfo['pageTotal'] , $this->sysInfo['page']+1 );
$prev = min( $this->sysInfo['pageTotal'] , $this->sysInfo['page'] );
$this->sysInfo['prev'] = max( 0 , $prev-1 );
return( true );
}
public function __get( $property )
{
/*
* 获取对象的关联信息
*
* @param string $property
* @access public
*/
switch( strtolower( $property ) )
{
case "key":
return( $this->sysInfo['key'] );
break;
case "value":
return( $this->sysInfo['value'] );
break;
case "table":
return( $this->sysInfo['table'] );
break;
case "where":
return( $this->sysInfo['where'] );
break;
case "recordtotal":
return( $this->sysInfo['recordTotal'] );
break;
case "maxpage":
return( $this->sysInfo['maxPage'] );
break;
case "restotal":
return( $this->sysInfo['resTotal'] );
break;
case "pagetotal":
return( $this->sysInfo['pageTotal'] );
break;
case "currenttotal":
return( $this->sysInfo['currentPageTotal'] );
break;
case "start":
return( $this->sysInfo['currentPageStart'] );
break;
case "end":
return( $this->sysInfo['currentPageEnd'] );
break;
case "next":
return( $this->sysInfo['next'] );
break;
case "prev":
return( $this->sysInfo['prev'] );
break;
case "sysinfo":
return( $this->sysInfo );
break;
default:
return( false );
}
}
public function getRecords( )
{
/*
* 获取数据库记录信息
*
* @access public
*/
if( !$this->data )
{
if( !self::query( ) )
{
return( false );
}
}
return( $this->data );
}
public function showError( )
{
return( $this->error->pross( ) );
}
public function __destruct( )
{
/*
* 释放对象占用的资源
*
* @access public
*/
$this->sql = NULL;
$this->sysInfo = NULL;
$this->data = NULL;
}
}
?>
相关文章推荐
- TP框架--利用自带分页处理自己数据的分页
- Java文章分页处理
- 特殊分页处理
- 数据分页处理系列之三:Neo4j图数据分页处理
- 如何优化Mysql千万级快速分页,limit优化快速分页,MySQL处理千万级数据查询的优化方案!(zz)
- Python+Selenium 自动化实现实例-处理分页(pagination)
- 随机排序分页处理示例
- 特殊分页处理
- 06-php雇员管理系统-实现显示雇员信息列表分页改进(可以处理大数据100000条)
- oracle 分页处理
- 基于Metronic的Bootstrap开发框架经验总结(2)--列表分页处理和插件JSTree的使用
- sybase的分页处理
- django分页处理
- 共享一个JS分页处理的类(2)
- 使用插件bootstrap-table实现表格记录的查询、分页、排序等处理
- jdbc心得-4-分页、元数据、大数据处理
- 对于分页时,若数据库的数据不断更新,不让前台显示脏数据(同一条数据重复显示)的处理方式
- javascript如何处理很多数据,类似分页切换
- 随机排序分页处理示例
- 有关spring中bean的@Scope 和richfaces 中表单分页的处理方式