How to Show Data to Get Same Column Data Only?

I've got some problem with modal. When I click the detail order button the table of detail product is not showing. Where is the fault in my code?

If I'm using the foreach $ordering it just shows 1 product and the other product is not shown. When I use foreach $detail_buyer it should show all product customer buy, but, when I'm trying it didn't show the product, it just shows modal bootstrap.

Example : When I clicked the ordering 00098 and the modal showing the detail orders with all product (1.. 2.. 3..).

I'm using a framework codeigniter with bootstrap template.

This is my View.

<h1>List Order</h1>
    <table class="table" width="900" border="0" cellspacing="1" cellpadding="1">
     <tr>
       <td width="250" align="center"><strong>Invoice</strong></td>
       <td width="200" align="center"><strong>Date Order</strong></td>
       <td width="160" align="center"><strong>Price</strong></td>
       <td width="250" align="center"><strong>Status</strong></td>
     </tr>
      <?php
        $no = $this->uri->segment(3) + 1;
        foreach($ordering as $row)
        {
      ?>
     <tr>
    <td align="center" valign="middle"><?php echo $row->invoice ?></td>
    <td align="center" valign="middle"> <?php echo poland_date($row->btn) ?></td>
    <td align="center" valign="middle">$<?php echo number_format($row->cart_total,2,',','.'); ?></td>
    <td align="center" valign="middle"><a href="#<?php echo $row->invoice; ?>" data-reveal-id="<?php echo 
    $row->invoice; ?>" class="btn btn-info btn-sm" data-toggle="modal">Detail</a>
 </td>

  </tr>
    <?php
            $no++;
        }
    ?>
</table>

<?php
        $no = $this->uri->segment(3) + 1;
        foreach($ordering as $row)
        {
?>
<div class="modal fade" id="<?php echo $row->invoice; ?>" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
    <<h3 class="modal-title">Detail Order <?php echo $row->invoice ?></h3>
    <button type="button" class="close" data-dismiss="modal">&times;</button>
  </div>

  <!-- Modal body -->
  <div class="modal-body">
    <table class="table table-striped">
      <thead>
      <tr>
        <th>Date</th>
        <th>Product</th>
      </tr>
      </thead>
      <?php
        $no = $this->uri->segment(3) + 1;
        foreach($list_product as $row)
        {
      ?>
      <tbody>
      <tr>
        <td> <?php echo $row->date;?></td>
        <td> <?php echo $row->product;?></td>
      </tr>
      </tbody>
      <?php
        $no++;
        }
      ?>
    </table>
    <br />
    <div align="center">
    <strong>Status :
    <?php 
        echo $row->status;  
    ?>
    </strong>
    </div>
    <br />
    <br />

  </div>

  <!-- Modal footer -->
  <div class="modal-footer">
    <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
  </div>
</div>
</div>
</div>
<?php
        $no++;
    }
?>

This is my Controller.

public function detail(){
        $this->check_logged_in();

        $id = $this->session->userdata('id');
        $email = $this->session->userdata('email');

        $data['ordering'] = $this->Buy_model->list_order_member($email);
        $data['list_product'] = $this->Buy_model->detail_buyer($hidden_id/*,$email*/);   
        $config['base_url'] = base_url().'Dashboard/detail/';
        $config['total_rows'] = $this->Buy_model->num_rows_detail($email);

        $this->load->view('frontend/detailpage',$data);
    }

This is my Buyer_model

public function list_order_member($email){
        $this->load->database();
        $this->db->order_by('date','desc');
        $this->db->group_by('invoice');
        $this->db->distinct();
        $this->db->where('email',$email);
        $query = $this->db->get('order');
        return $query->result();
    }

public function detail_buyer($hidden_id/*,$email*/){
        $this->load->database();
        $this->db->order_by('qty','desc');
        $this->db->where('invoice',$hidden_id);
        $query = $this->db->get('order');
        return $query->result();
    }

[UPDATE] When I use this script.

<tbody>
            <?php
              $no = $this->uri->segment(3) + 1;
              $list_detail = $this->db->query("select * from order where invoice = '$rows->invoice'");
              foreach($list_detail->result_array() as $buys)
              {
            ?>
          <tr>
            <td> <?php echo $buys->date;?></td>
            <td> <?php echo $buys->product;?></td>
          </tr>
          <?php
            $no++;
            }
          ?>    
          </tbody>

The list/rows data showing exactly true, but with blank data :(

enter image description here

2 answers

  • answered 2019-12-12 08:59 Dmitry

    If result is array you need try code below:

    <tbody>
    <?php
    $no = $this->uri->segment(3) + 1;
    $list_detail = $this->db->query("select * from order where invoice = '$rows->invoice'");
    foreach ($list_detail->result_array() as $buys) {
        ?>
            <tr>
                <td> <?php echo $buys['date']; ?></td>
                <td> <?php echo $buys['product']; ?></td>
            </tr>
        <?php
        $no++;
    }
    ?>
    </tbody>
    

  • answered 2019-12-12 09:16 Anand Pandey

    There are result_array() is used and you are echo by ->(arrow) operator. You have to change the line of code.

    <?php
      $no = $this->uri->segment(3) + 1;
      $list_detail = $this->db->query("SELECT * FROM order WHERE invoice = '$rows->invoice'");
      foreach($list_detail->result() as $buys) //here is the changes made
      {
    ?>
        <tr>
            <td><?php echo $buys->date;?></td>
            <td><?php echo $buys->product;?></td>
        </tr>
    <?php
        $no++;
    }
    ?>    
    </tbody>