Welcome Guest, Not a member yet? Register   Sign In
Manage an empty query
#3

There is more than one way to handle this. In your case it might be most easily done by not returning FALSE from the model. Why? Because $query->result() returns an empty array when no records are found and that fact can be used in the view.

Here's a revised model that potentially will return an empty array.

PHP Code:
 public function biens_location()
 
 {
 return 
$this->db->select('')
 ->
from('biens')
 ->
where('actif''1')
 ->
where('rent''1')
 ->
get()
 ->
result();
 
 

Your controller is unchanged.

On the view your check the var and respond with your message if the var is empty.

PHP Code:
if(empty$biens))
{
 
   echo "There are no properties for rent.";
}
else
{
 
  foreach ($biens as $bien)
 
  {
 
     ...
 
  }


You could also leave the model as is and revise your controller to conditionally provide an empty array to the view just described.

PHP Code:
public function location()
{
 
 $data $this->Biens_model->biens_location();
 
 if($data === FALSE)
 
 {
 
    $data = array();
 
 }
 
 $this->data['biens'] = $data;
 
 $this->data['title'] = "Location";
 
 $this->render('location_view');

Reply


Messages In This Thread
Manage an empty query - by cybersven - 03-28-2017, 04:03 AM
RE: Manage an empty query - by cybersven - 03-28-2017, 06:18 AM
RE: Manage an empty query - by dave friend - 03-28-2017, 06:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB