Welcome Guest, Not a member yet? Register   Sign In
return values
#1

New to PHP and Codeigniter, but have experience in the Microsoft world (.NET, MSSQL).

I recently agreed to help a friend with a website. He's more of a design person and doesn't understand the backend/db portion, so I agreed to help him We are using Codeigniter as the framework.

Can someone give me some patterns of how to deal with getting data from a table but not getting any results back?

One of the views deal with a user using dropdowns to search for things in a table. I would like to know when there is no result and maybe give a modal saying that there was nothing it found.

Thanks in advance for your help.
Reply
#2

Normally I would have in my model something like

PHP Code:
public function get_something() 
{
     $results FALSE;
     ...
     $query $this->db->get();
     if ($query->num_rows() > 0)
     {
          $results $query->result_array();
     }
     return $results;


And in the controller you can just test if the return value is FALSE or not.

PHP Code:
     $data $this->some_model->get_something();
     if ($data)
     {
          ... deal with data
     
}
     else
     
{
          ... deal with no data
     


Or you can send the data to the view and deal with the FALSE condition in the view.

Hope that helps,

Paul
Reply
#3

(05-29-2016, 08:33 AM)This is perfect. Thank you so much for the examples!---- PaulD Wrote: Normally I would have in my model something like

PHP Code:
public function get_something() 
{
     $results FALSE;
     ...
     $query $this->db->get();
     if ($query->num_rows() > 0)
     {
          $results $query->result_array();
     }
     return $results;


And in the controller you can just test if the return value is FALSE or not.

PHP Code:
     $data $this->some_model->get_something();
     if ($data)
     {
          ... deal with data
     
}
     else
     
{
          ... deal with no data
     


Or you can send the data to the view and deal with the FALSE condition in the view.

Hope that helps,

Paul
Reply




Theme © iAndrew 2016 - Forum software by © MyBB