skip to Main Content

The issue is that, I am only getting the last data from the above function. In my database, I have four categories listed in my database but only receiving the data from the last query. How can I get rid of this? I have tried multiple variations over here.

I have also tried normal sql queries with the same, but I got the data from last id only.

 foreach($category as $cat){

     $cat_id = $cat->id;
     $data['catalog'] = $this->homemodel->getCatalog($cat_id);
 }

      

2

Answers


  1. Try like this

    $i = 0;
    foreach($category as $cat)
    {
       $cat_id = $cat->id;
       $data['catalog'] = $this->homemodel->getCatalog($cat_id);
       $i++;
    }
    
    Login or Signup to reply.
  2. Replace Your Code with below code

    foreach($category as $cat){
    
         $cat_id = $cat->id;
         $data['catalog'][] = $this->homemodel->getCatalog($cat_id);
     }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search