I have 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 variable $ cat_id correctly stores the values of my query, when I echo:
foreach ($query->result() as $row):
$cat_id = $row->category_id;
echo $cat_id;
endforeach;
But if the 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 just the last id stored.
I need to store all 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 this?
Thank you.