Reputation: 17383
I'm using codeigniter
framework.
how can I do check get
function is empty or not?
...
$result = $this->db->get()
//how to check $result is empty or not ?
Upvotes: 1
Views: 4535
Reputation: 7059
Better way according to Codeigniter Active records Documentation
$query = $this->db->get('mytable');
if($query->num_rows() > 0) {
foreach ($query->result() as $row){
echo $row->title;
}
}
else{
//no record found.
}
Upvotes: 1
Reputation: 19
$result = $this->db->get('myTable')->result();
print_r($result);die();
Upvotes: 0
Reputation: 526
$result = $this->db->get()->result_array();
Now check $result value its empty or not.
if(!empty($result)){
//code if not empty
}
else{
//code if empty
}
Upvotes: 0
Reputation: 1488
You can check like below,
$result = $this->db->get() ;
if($result->num_rows() != 0){
//you can do anything with data here
}
else{
//empty
}
Upvotes: 0
Reputation: 743
You can do it this way
$query = $this->db->get();
if ($query->num_rows() > 0) {
//record exists - hence fetch the row
$result = $query->row();
}
else
{
//Record do not exists
}
Upvotes: 3