php分页类

?phpclass conn{function __construct(){ require(config.php); $conn =
@mysql_connect($host,$root,$pass); @mysql_select_db($db); if(!$conn){
echo 无法连接.mysql_errno() . : . mysql_error() ; exit; }}function
query($sql){ $result = @mysql_query($sql); if (!$result) { echo
mysql_errno().:.mysql_error(); exit; } return $result;}function
next($result){ return @mysql_fetch_array($result);}function
count_row($result){ $row = @mysql_num_rows($result); return
$row;}function close($result){ @mysql_澳门新葡亰3522平台游戏,free_result($result);
@mysql_close();}}class fenye extends conn{public $sql;public
$page;public $countpage;public $pagesize;public $result;function
__construct($sql,$page,$pagesize){ $this-sql = $sql; $this-page =
$page; $this-countpage = $countpage; $this-pagesize = $pagesize;
parent::__construct(); $result = parent::query($sql); $num =
parent::count_row($result); $this-countpage = ceil($num/$pagesize); $a
= ($page-1)*$pagesize; $limit = limit $a,$pagesize; $this-sql =
$sql.$limit; $this-result = parent::query($this-sql);}function
getlimit(){ return $this-sql;} function next(){ return
parent::next($this-result); }function foor(){ $a = $this-page -1; $b =
$this-page +1; if ($this-page == 1) { echo 首页. ; }else echo a
href=’?page=1’首页/a. ; if($this-page 1) echo a href=’?page=$a’上页/a. ;
else echo 上页 ; for ($i =1;$i = $this-countpage;$i++){ echo a
href=’?page=$i’$i/a. ; } if($this-page $this-countpage) echo a
href=’?page=$b’下页/a. ; else echo 下页 ; if ($this-page ==
$this-countpage) { echo 末页. ; }else echo a
href=’?page=$this-countpage’末页/a;
#######################
}}####################if (isset($_GET[‘page’]))
{$page = $_GET[‘page’];}else $page = 1;$sql = select * from
guestbook ;$pagesize =3;$p = new fenye($sql,$page,$pagesize); $sql =
$p-getlimit();$result = $p-query($sql);while($row = $p-next()){echo
$row[‘id’].br;}$p-foor();$p-close($result);?