Welcome Guest, Not a member yet? Register   Sign In
Can't display data in views.
#5

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) {
    foreach (
$query_result as $key => $value) {
        echo 
"<li><a href='#'>{$value->Component_Type_Name}</a></li>";
    }


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 
FROM component_list 
LEFT OUTER JOIN component_type_list ON component_list.Component_Type_ID = component_type_list.Component_Type_ID
WHERE 20x20_Rail = '1' OR 20x40_Rail = '1' OR 20x60_Rail ='1';"


Then you wouldn't need the foreach() loop in your model and the original code you supplied for the view should work fine.
Reply


Messages In This Thread
Can't display data in views. - by rhyszz - 09-20-2015, 08:32 PM
RE: Can't display data in views. - by rhyszz - 09-20-2015, 10:08 PM
RE: Can't display data in views. - by mwhitney - 09-21-2015, 07:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB