 <?php
 /*
    获取当前页数据类 　
    version：1.0
    author：侯爷的博客
    www.palmcivet.ren
    Date：2016-5-21
    */
    
    /*调用示例
$sql = "select * from product where pid=1";
$mypage = new getcurdata($sql);
$mydata = $mypage->getdata();
if($mydata){
echo "ID号：".$mydata->pid."<br>";
echo "名称：".$mydata->pname."<br>";
echo "共有：".$mypage->getfields()."列";
}
    */
 
class getcurdata{
	
	private $getfields;
  private $result;
  private $pdata;
  private $psqlstr;//查询的SQL语句
  private $lm_id;
  private $table;
 
function __construct($getselect){
$this->lm_id = isset($_GET['id']) ? cinput($_GET['id']) : 0;
switch($getselect){
case 1:
$this->table = "limao_article";
break;
case 2:
$this->table = "limao_shop";
break;
default:

}
$this->psqlstr = "select * from $this->table where lm_id=".mysql_real_escape_string($this->lm_id);
$result = mysql_query($this->psqlstr);
if($result){
$pdata = mysql_fetch_object($result);
$this->result = $result;
$this->pdata = $pdata;
}else{
echo "<script>alert('传入的参数错误,系统正返回首页');location.href='index.php';</script>";	
}
}
//返回记录集总列数
 function getfields(){
$this->getfields = mysql_num_fields($this->result);
return $this->getfields;
	}
//返回当前数据
 function getdata(){
 	if($this->pdata){
return $this->pdata;
}else{
echo "<script>alert('查询ID号失败,系统正返回首页');location.href='index.php';</script>";
return false;
	}
	}

}
    ?>