 <?php
 /*
    分页类 用于实现对多条数据分页显示　
    version：1.0
    author：侯爷的博客
    E-Mail：yixianbinbink@gmail.com
    Date：2016-5-20
    */
    
    /*
       或  $pages = new Page('SELECT * FROM `zy_common_member`', 10,string);
    */
  class fpage{
	
	private $cpage;//当前页
  private $pagecount;//总页数
  private $amount;//查询总记录数
  private $PageSize;//每页多少条记录
  private $psql;//查询的SQL语句
  private $pstring;
function __construct($psql,$PageSize,$pstring){
$result = mysql_query($psql);
$amount = mysql_num_rows($result);
$this->amount = $amount;
$this->pagecount = ceil($amount / $PageSize);
$this->psql = $psql;
$this->pstring = $pstring;
$this->PageSize = $PageSize;
$temp = (isset($_GET['page']) ? $_GET['page'] : 1);
$this->getpage($temp);

}

//返回总记录数
function getamount(){
echo $this->amount;
	}
//返回总页数
function getpagecount(){
echo $this->pagecount;
	}
//获取当前页
function getpage($cpage){
	if(isset($cpage)){
 if(is_numeric($cpage)){                              	
$cpage = intval($cpage);
if($cpage>=$this->pagecount){
$cpage = $this->pagecount;
        }
 if($cpage<=0){
$cpage = 1;
 }
}else{
 $cpage = 1;
    }
   }else{
 $cpage = 1;
    } 
	 $this->cpage = $cpage;
}

function showCurPage(){
	
             $this->limitStr = ' LIMIT '.(($this->cpage - 1)* $this->PageSize).','.$this->PageSize;
            //echo $this->queryStr.$this->limitStr;
            $rsdata = mysql_query($this->psql.$this->limitStr);
              return $rsdata;
        }


//页码
function getfoot(){
	
	if($this->cpage==1){   
 echo '首页&nbsp;上一页&nbsp;';
       
         }
         else{   	
      echo '<a href="?page=1'.$this->pstring.'">首页</a>&nbsp;<a href="?page='.($this->cpage-1).$this->pstring.'">上一页</a>&nbsp;';
        
        }
                  
 if(($this->cpage==$this->pagecount)||($this->pagecount==0)){
 echo '下一页&nbsp;尾页';
          }
          else{
 echo '<a href="?page='.($this->cpage+1).$this->pstring.'">下一页</a>&nbsp;<a href="?page='.$this->pagecount.$this->pstring.'">尾页</a>';
           
           }
        
  echo  "&nbsp;共有".$this->pagecount."页,当前第".$this->cpage."页,每页显示".$this->PageSize."条记录";	
	

 
}


}
    ?>