我想获取数据和条件但在codeigniter中发生未知错误

时间:2014-05-02 10:47:29

标签: php codeigniter

我的代码是...我在codeigniter中获取数据和条件但是 发生了一些错误...我的模型就是这样......“

 public function hospital_edit($param = null){

     $Hospitals_id = $param;
     $status = 1;
     $this->db->select('*');
     $this->db->from('wl_hospitals');
     $this->db->where('Hospitals_id', $Hospitals_id);
     $this->db->where('Hospitals_status',$status);
     $result = $this->result();
    echo "<pre>"; print_r($result);exit;

 }

3 个答案:

答案 0 :(得分:0)

如果不在查询中调用get(),则无法直接获取结果请尝试此

$Hospitals_id = $param;
$status = 1;
$query=$this->db
            ->select('*')
            ->from('wl_hospitals')
            ->where('Hospitals_id', $Hospitals_id)
            ->where('Hospitals_status',$status)
            ->get();
$result = $query->result();  

答案 1 :(得分:0)

试试这个

public function hospital_edit($param = null){

     $Hospitals_id = $param;
     $status = 1;
     $this->db->where('Hospitals_id', $Hospitals_id);
     $this->db->where('Hospitals_status',$status);
     $query = $this->db->get('wl_hospitals');
    if($query->num_rows()>0){
         $result = $query->result();
    }else{
      echo "No Data";
     }

 }

答案 2 :(得分:0)

试试这个:

public function hospital_edit($param = null){

 $Hospitals_id = $param;
 $status = 1;
 $hospitals = $this->db->get_where('wl_hospitals', array('Hospitals_id' => $Hospitals_id,'Hospitals_status' => $status));
 $result = $hospitals->result();

}