我无法在 codeigniter 中正确显示视图。我一直在尝试使用 foreach 循环

I am not able to display View properly in codeigniter. Using foreach loop I have been trying

在这里您可以查看 output

这是我的控制器:-

public function order_info()
{
    $this->load->model('customize_model');
   $data['user'] = $this->customize_model->order_info();
   $data['product']=$this->customize_model->order_info();
   $data['sale'] = $this->customize_model->order_info();
    $this->load->view('custom/order',$data);
}

这是我的模态:-

 public function order_info()
  {
   $query = $this->db->query("SELECT *
    FROM user
    JOIN product
    ON user.user_id = product.product_id 
    JOIN sale
    ON user.user_id = sale.buyer
    ORDER BY user_id DESC LIMIT 100;");   
    return $query;
 }

这是视图:-

<?php foreach($sale->result() as $row)
   {
      $order_id = $row->sale_id;                                 
      $grand_total = $row->grand_total;
      $status = $row->status;
  ?>
      <tr>     
         <td><?php echo $order_id;?></td>
         <td><?php echo $username;?></td>
         <td><?php echo $productname?></td>
         <td><?php echo $grand_total;?></td>
         <td><?php echo $status;?></td>     
       </tr> 
       <?php 
         foreach($user->result() as $row1)
         {
          $username = $row1->username;  
          foreach($product->result() as $row2)
          {
            $productname = $row2->title;                                  
           }
          }
        }
 ?>   

在我看来,我一直坚持以单个 table 显示记录。 问题就在眼前。 foreach 循环在这种格式下不起作用,我应该用它来解决它。

尝试在您的视图中这样做:-

<?php foreach($sale->result() as $row)
   {
      $order_id = $row->sale_id;                                 
      $grand_total = $row->grand_total;
      $status = $row->status;
  ?>
      <tr>     
         <td><?php echo $order_id;?></td>
         <td><?php echo $row->username; ?></td>
         <td><?php echo $row->title; ?></td>
         <td><?php echo $grand_total;?></td>
         <td><?php echo $status;?></td>     
       </tr> 
       <?php 
        }
 ?>