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

Time:01-19

Here you can view the output

Here is my controller:-

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);
}

And here is my modal:-

 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;
 }

This is view:-

<?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;                                  
           }
          }
        }
 ?>   

Here in my view I got stuck with displaying records, in single table. problem is in view. foreach loop doesn't work in this format which shall i use to solve it.

CodePudding user response:

Try doing this in your view:-

<?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 
        }
 ?>   

  •  Tags:  
  • Related