Manage an empty query |
Hi,
I got a model : PHP Code: public function biens_location() PHP Code: public function location() PHP Code: foreach ($biens as $bien) Everything is Ok, but in the case there is no result I got an error so I would like to check results and show a message on the page something like "There are no properties for rent". How can I achieve this ?
Ok I answered myself, I've just modified the controller to test the result true or false and set the correct variables to pass...
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() 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)) 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() |
Welcome Guest, Not a member yet? Register Sign In |