2016-10-06 53 views
0

通過ID當我笨是新錯誤的引導模式

<?php foreach ($rows as $row) { ?> 
    <tr> 
    <td><?php echo $i++;?></td> 
    <td><?php echo $row->orderid;?></td> 
    <td><?php echo $row->order_date;?></td> 
    <td><?php echo $row->name;?></td> 
    <td><?php echo $row->price;?></td> 
    <td> 
     <button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#myModal-<?= $row->customerid?>">View Details</button> 
    </td> 
    </tr> 
    <div class="modal fade" id="myModal-<?= $row->customerid?>" role="dialog"> 
    <div class="modal-dialog modal-sm"> 
     <div class="modal-content"> 
     <div class="modal-header"> 
      <button type="button" class="close" data-dismiss="modal">&times;</button> 
      <h4 class="modal-title">Order Details</h4> 
     </div> 
     <div class="modal-body"> 
      <p><strong>Product Name</strong>:&nbsp;&nbsp;&nbsp;<?php echo $row->name;?></p> 
      <p><strong>Quantity</strong>:&nbsp;&nbsp;&nbsp;<?php echo $row->quantity;?></p> 
      <p><strong>Price</strong>:&nbsp;&nbsp;&nbsp;<?php echo $row->price;?></p> 
     </div> 
     <div class="modal-footer"> 
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
     </div> 
     </div> 
    </div> 
    </div> 
<?php } ?> 

僅第一行的詳細信息會顯示在所有模態 我需要從每個模態

+0

顯示您爲編寫數據所寫的查詢 –

+0

public function list_orders(){ $ this-> data ['rows'] = $ this-> order_model-> get_orders(); $ this-> load-> view('list_orders',$ this-> data); } – gokul

+0

這是我的控制器功能 – gokul

回答

0

我可以用bootbox模式插件(http://bootboxjs.com/)來幫助你。修改你的HTML如下

<div id="myModal" class="modal fade"> 
     <div class="modal-dialog"> 
     <div class="modal-content"> 
      <!-- dialog body --> 
      <div class="modal-body"> 
      <button type="button" class="close" data-dismiss="modal">&times;</button> 
      <div></div> 
      </div> 
     </div> 
     </div> 
    </div> 

然後刪除按鈕代碼,並使用此代碼

<a class="btn btn-primary your_defined_class_name_for_jquery_use" data-id="<?php echo $row['whatever_id']?>" > What ever name</a> 

取代添加在頁面的底部

<script>$(className).on('click','your_defined_class_name_for_jquery_use', function (e) { 
    var id=$(this).data('id'); 
    var dialog = bootbox.dialog({   
     title: title, 
     message: $('<div></div>').load(url_to_your_controller_which_shows_the_data), 

    }); 

}); 

確保下面的腳本jquery以前被加載在頁面上。我認爲這會幫助你。

+0

謝謝你以某種方式我得到了答案我也有錯誤在ID也 – gokul

+0

你是最受歡迎的。 –

0

嘗試獲取每個細節與波紋管代碼:

function get_orders(){ 
    $this->db->select('*'); 
    $this->db->from('orders o'); 
    $this->db->join('order_detail od', 'o.serial = od.orderid', 'left'); 
    $this->db->join('tbl_products p', 'p.prod_id = od.productid', 'left'); 
    $query = $this->db->get(); 
    return $query->result(); 
} 

使用此行$this->db->join('order_detail od', 'o.serial = od.orderid', 'left');$this->db->join('order_detail od', 'od.orderid = o.serial','left');