Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 选中$this->;db->;get()是否为空_Php_Codeigniter - Fatal编程技术网

Php 选中$this->;db->;get()是否为空

Php 选中$this->;db->;get()是否为空,php,codeigniter,Php,Codeigniter,我正在使用codeigniter框架 如何检查get函数是否为空 ... $result = $this->db->get() //how to check $result is empty or not ? 你可以这样做 $query = $this->db->get(); if ($query->num_rows() > 0) { //record exists - hence fetch the row $res

我正在使用
codeigniter
框架

如何检查
get
函数是否为空

...
$result = $this->db->get() 
 //how to check $result is empty or not ?
你可以这样做

$query = $this->db->get();
if ($query->num_rows() > 0) {
  //record exists - hence fetch the row              
  $result = $query->row();               
} 
else
{
  //Record do not exists
}

你可以像下面这样检查

$result = $this->db->get() ;

if($result->num_rows() != 0){
  //you can do anything with data here
}
else{
  //empty
}

根据

现在检查$result值是否为空

if(!empty($result)){
//code if not empty
}
else{
//code if empty
}

您可以使用
if($result->num_rows())
通常需要一些解释
$result = $this->db->get()->result_array();
if(!empty($result)){
//code if not empty
}
else{
//code if empty
}
$result = $this->db->get('myTable')->result();
print_r($result);die();