 <?php
 /*
    分页类 用于实现对多条数据分页显示　
    version：1.0
    author：侯爷的博客
    www.palmcivet.ren
    Date：2016-5-20
    */
    
   
  class listpage{
	
	private $cpage;//当前页
  private $pagecount;//总页数
  private $amount;//查询总记录数
  private $PageSize;//每页多少条记录
  private $nmtype;//类型
  private $nmtable;
  private $pid;
  private $psql;//查询的SQL语句
  private $pstring;
  private $nmid;
function __construct($pid,$PageSize,$pstring){
$pid = isset($_GET['lm_rjnmid']) ? cinput($_GET['lm_rjnmid']) : cinput($pid);
if(!is_numeric($pid)){
		echo "<script>alert('传入的参数错误,系统正返回首页');location.href='index.php';</script>";
exit();
	}else{
$this->pid = intval($pid);
}
$nmsql = "select * from limao_nm where lm_id=$this->pid limit 1";
$nmrs = mysql_query($nmsql) or die('传入参数错误'.mysql_error());
$nmdata = mysql_fetch_object($nmrs);
if($nmdata){
$this->nmtype = $nmdata->lm_error;
$this->nmid = intval($nmdata->lm_nmid);
$this->getptype();
}
$this->pstring = $pstring;
$this->PageSize = $PageSize;
$this->getcanshu();

$temp = (isset($_GET['page']) ? $_GET['page'] : 1);
$this->getpage($temp);

}
//返回类型
function getptype(){
switch($this->nmtype){
	case 1:
	$this->nmtable = 'limao_article';
	$this->psql = "select * from $this->nmtable where lm_type=$this->pid order by lm_id desc";
	break;
  case 2:
  $this->nmtable = 'limao_shop';
  $this->psql = "select * from $this->nmtable where lm_type=$this->pid order by lm_id desc";
break;
	}
	}
	
//返回总记录数总页数
function getcanshu(){
$result = mysql_query($this->psql);
if($result){
$amount = mysql_num_rows($result);
$this->amount = $amount;
$this->pagecount = ceil($this->amount / $this->PageSize);	
}
	}
	

		
//返回总记录数
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);
          if($rsdata){
              return $rsdata;
            }else{
            	echo "没有数据";
            	}
         
        }


//页码
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."条记录";	
	

 
}


}
    ?>