0

I have a category table and a product table, i want to fetch all the category and for each category it should display the products associated to that category , but i can't seem to put them in order

 $get_cat = $this->AdminModel->getcategorie();

  foreach($get_cat as $cats){

    $cats->id = $this->AdminModel->getproducts($cats->id);
     
  }

$data=['prod'=>$get_cat];

enter image description here

so the places that shows 0 and 1 should display the categories name but instead it is being displayed in the product table

if i do a var_dump() on $pros this is what i get

enter image description here

so how can I display categories name and the products associated with that categories

Here is the loop with the HTML tag

 <?php foreach($data['prod']  as $cats => $pros) :?>
  <div class="container-fluid">
    <!-- SELECT2 EXAMPLE -->
    <div class="card card-default collapsed-card">
      <div class="card-header">
        <h3 class="card-title"><?php echo $cats; ?></h3>

    <div class="card-body">
          <table class="table table-bordered table-striped">
            <thead>
              <tr>
                                            <th>#</th>
                                            <th>Product Name</th>
                                            <th>Edit</th>
                                            <th>Delete</th>
               
              </tr>
              </thead>
              <tbody>
                             <?php $i=1;  foreach($pros as $pro): ?>
                                 <tr>
                                                        <td><?php echo $i++; ?></td>
                                                        <td><?php echo $pro ?></td>
                                                         
                                                        <td>Edit</td>
                                                        <td>Delete</td>
                                                    
                                         
                                        </tr>


                                        <?php endforeach; ?>

                                      
                                    
              </tbody>
            </table>

0 Answers0