<?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;
}
}
?>