<?php    	  
  class page{
  	public  $sql;
  	public  $pageSize;
  	public  $url;
  	public  $page;
  	public  $conn;
  	public  function __construct($sql,$pageSize,$url,$page,$conn){
  		$this->sql=$sql;
  		$this->pageSize=$pageSize;
  		$this->url=$url;
  		$this->page=$page;
  		$this->conn=$conn;
  	}
  	
  	public  function getPage(){
  		$result=mysql_query($this->sql,$this->conn);
  		$totalNum=mysql_num_rows($result);
  		$pageNum=ceil($totalNum/$this->pageSize);
  		$start=($this->page-1)*$this->pageSize;
  	    $end=$this->pageSize;
  		$sql=$this->sql."limit $start,$end";
  		$result1=mysql_query($sql);
  		while ($row1=mysql_fetch_array($result1,MYSQL_ASSOC)) {
  			$row[]=$row1;
  		}
  		foreach ($row	as $key=>$value){
	     $row[$key]=$value;
        }
  		return $row;
  	}
  	public function pageBar(){
  	
  		$result=mysql_query($this->sql,$this->conn);
  		$totalNum=mysql_num_rows($result);
  		$pageNum=ceil($totalNum/$this->pageSize);
  		$homePage="<a href=\"".$this->url."page=1\">首页<a/>";
  		if($this->page==1){
  			$prepage=null;
  		}else{
  			$prepage1=$this->page-1;
  			$prepage="<a href=\"".$this->url."page=$prepage1\">上一页</a>";
  		}
  		if($this->page==$pageNum){
  			$nextPage=null;
  		}else{
  			$nextPage1=$this->page+1;
  			$nextPage="<a href=\"".$this->url."page=$nextPage1\">下一页</a>";
  		}
  		$endPage="<a href=\"".$this->url."page=$pageNum\">最后一页</a>";
  		$pageBar="<span>总共&nbsp;$pageNum&nbsp;页</span>&nbsp;&nbsp;<span>当前&nbsp;$this->page&nbsp;页</span>&nbsp;&nbsp;<span>$homePage</span>&nbsp;&nbsp;<span>$prepage</span>&nbsp;&nbsp;<span>$nextPage</span>&nbsp;&nbsp;<span>$endPage</span>";
  	    return $pageBar;
  	}
  }
?>