When i run this query for API. I am getting allowed memory size of 134217728 bytes exhausted.
Query is
public function categories_with_products(){
$this->db->select('category_id,category_name,parent_category');
$this->db->from('categories_info');
$this->db->where('parent_category', 1);
$parent = $this->db->get();
$categories = $parent->result();
$i=0;
foreach($categories as $p_cat){
$categories[$i]->sub_categories = $this->sub_categories_with_products($p_cat->category_id);
$i++;
}
return $categories;
/* echo json_encode (
array('cat'=>$categories,
));*/
}
public function sub_categories_with_products($id){
$this->db->select('category_id,category_name,parent_category');
$this->db->from('categories_info');
$this->db->where('parent_category', $id);
$child = $this->db->get();
$categories = $child->result();
$i=0;
foreach($categories as $p_cat){
$categories[$i]->sub_category = $this->sub_categories_products($p_cat->category_id);
$i++;
}
return $categories;
}
public function sub_categories_products($id){
$this->db->select('product_name,category_id');
$this->db->from('products_info');
$this->db->where('category_id', $id);
$child = $this->db->get();
$categories = $child->result();
$i=0;
foreach($categories as $p_cat){
$categories[$i]->products = $this->sub_categories_products($p_cat->category_id);
$i++;
}
return $categories;
}