![]() |
Codeigniter - get only 1 row from table - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Codeigniter - get only 1 row from table (/showthread.php?tid=1544) |
Codeigniter - get only 1 row from table - GrigoreMihai - 03-20-2015 I know this is a noob question but atm I can't figure out what i'm doing wrong. I have model : PHP Code: public function getRow($id, $table) { and in view : PHP Code: <?php echo $data->column_name; ?> This work but if there are no records I get : Trying to get property of non-object .. I can't for the life of me remember how I fix the problem last time ... RE: Codeigniter - get only 1 row from table - algenza - 03-20-2015 filter $data to check if it is NULL (No Records) before displaying it RE: Codeigniter - get only 1 row from table - suhindra - 03-20-2015 In your controller add code like this PHP Code: public function view($id) RE: Codeigniter - get only 1 row from table - GrigoreMihai - 03-20-2015 (03-20-2015, 03:07 AM)suhindra Wrote: In your controller add code like this That can't help at all .. Since i don't want to display a error page. I need to get records from a row and display then ( ' works' ) and if the return is NULL to display "nothing" at the section where I wanted to display them .. not to give error ... RE: Codeigniter - get only 1 row from table - suhindra - 03-20-2015 (03-20-2015, 03:13 AM)GrigoreMihai Wrote: That can't help at all .. Since i don't want to display a error page. I need to get records from a row and display then ( ' works' ) and if the return is NULL to display "nothing" at the section where I wanted to display them .. not to give error ... How about add if(isset()) in your view? PHP Code: <?php RE: Codeigniter - get only 1 row from table - CroNiX - 03-20-2015 Since you return NULL if none are found, then in your view you'd need to test for that and display a message or something. PHP Code: <?php if (is_null($data)): ?> RE: Codeigniter - get only 1 row from table - GrigoreMihai - 03-22-2015 Thanks .... works perfect ... forgot about is_null and isset .... |