I can't display the value in my views.
model code
PHP Code:
function get_subcat(){
$s_sub_category = array();
$sql = "SELECT DISTINCT Component_Type_ID FROM component_list WHERE 20x20_Rail = '1' OR 20x40_Rail = '1' OR 20x60_Rail ='1';";
$query = $this->db->query($sql);
if ($query->num_rows() > 0){
$result = $query->result();
foreach ($result as $key => $value) {
$get_compo_id_value = $value->Component_Type_ID;
$sql = "SELECT Component_Type_Name FROM component_type_list WHERE Component_Type_ID = $get_compo_id_value";
$query = $this->db->query($sql);
$s_sub_category[] = $query->result();
}
return $s_sub_category;
}
else{
return '';
}
}
controller
PHP Code:
$data['sub_category'] = $this->Component_model->get_subcat();
//load the view
$this->load->view('component_page',$data);
View
PHP Code:
<?php
foreach ($sub_category as $key => $value) {
echo '<li><a href="#">'.$value->Component_Type_Name.'</a></li>';
}
?>
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