Can't display data in views. |
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
(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();
There's only one rule - please don't tell anyone to go and read the manual. Sometimes the manual just SUCKS!
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.
(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 ?
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. |
Welcome Guest, Not a member yet? Register Sign In |