1
I’m having a problem storing the array values in the code below:
public function get_submenu() {
$query = $this->db->get_where('categories', array('category_id_parent' => 0));
foreach ($query->result() as $row):
$cat_id = $row->category_id;
endforeach;
if ($cat_id != FALSE):
$this->db->from('categories');
$this->db->where('category_id_parent', $cat_id);
$query = $this->db->get();
return $query;
else:
return FALSE;
endif;
}
Inside the loop the $cat_id variable correctly stores the values of my query, when I echo in:
foreach ($query->result() as $row):
$cat_id = $row->category_id;
echo $cat_id;
endforeach;
But if echo is out of the loop, like this:
foreach ($query->result() as $row):
$cat_id = $row->category_id;
endforeach;
echo $cat_id;
What returns is only the last stored id.
I need to store all the values of the $cat_id array to retrieve in the subsequent if block:
if ($cat_id != FALSE):
$this->db->from('categories');
$this->db->where('category_id_parent', $cat_id);
$query = $this->db->get();
return $query;
else:
return FALSE;
endif;
How do I do that?
Grateful.
Thank you Diego.
– Downbeat