Can't display data in views. - 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: Can't display data in views. (/showthread.php?tid=63050) |
Can't display data in views. - rhyszz - 09-20-2015 I can't display the value in my views. model code PHP Code: function get_subcat(){ controller PHP Code: $data['sub_category'] = $this->Component_model->get_subcat(); View PHP Code: <?php i get this error: Trying to get property of non-object i tried to check if there is a data in my array using print_r and display the data. thanks in advance RE: Can't display data in views. - wolfgang1983 - 09-20-2015 (09-20-2015, 08:32 PM)rhyszz Wrote: I can't display the value in my views. Perhaps try with Code: $result = $query->result_array(); RE: Can't display data in views. - rhyszz - 09-20-2015 i still got the same error. i conduct some test with my model PHP Code: foreach ($result as $key => $value) { i return the value inside the forloop but i gives me 1 record only. RE: Can't display data in views. - DEV03-ROMAIN - 09-21-2015 (09-20-2015, 08:32 PM)rhyszz Wrote: I can't display the value in my views. can you post the print_r of $data['sub_category'] before sending to your view ? RE: Can't display data in views. - mwhitney - 09-21-2015 From your original model code: PHP Code: $s_sub_category[] = $query->result(); That line should create a new entry in the $s_sub_category array which contains an array containing 0 or more objects (the rows returned by your query). So, if you leave your model the way it was, you would just need an additional foreach() loop in the view: PHP Code: foreach ($sub_category as $query_result) { However, it would make more sense to use a join in the original query to select the Component_Type_Name alongside the Component_Type_ID in a single query, rather than performing an additional query for each row returned by the original query. Something like this should work: PHP Code: $sql = "SELECT DISTINCT Component_Type_ID, Component_Type_Name Then you wouldn't need the foreach() loop in your model and the original code you supplied for the view should work fine. |