我有一個表中的模態。我從一個foreach表加載模態。我相信我的代碼是正確的,但我不知道它爲什麼顯示在一個有趣的方式。這是我的代碼,當我運行這段代碼時,這是我得到的結果。點擊鏈接查看圖像image從另一個foreach表中調用的模式加載foreach表
<tbody>
<?php
$count = 1;
$notarray = DataDB::getInstance()->select_from_where('order_collective','user_id',$userid);
foreach($notarray as $row):
$address = $row['appartment'].",".$row['address'].",".$row['city'].",".$row['state'].".".$row['landmark'];
?>
<tr>
<td><?php echo $count++;?></td>
<td><?php echo $row['trackingnumber'];?></td>
<td><?php echo "NGN ".number_format($row['price'], 2);?></td>
<td><?php echo $address;?></td>
<td><?php echo $row['order_date'];?></td>
<td><?php echo DataDB::getInstance()->get_name_from_id('name','delivery_status','delivery_status_id',$row['delivery_status']);?></td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#myVie<?php echo $row['trackingnumber'] ?>">View</button>
</div>
</td>
</tr>
<?php include ('order_history_modal.php'); ?>
<?php endforeach;?>
</tbody>
<!-- ORDER HISTORY Modal content-->
<div id="myVie<?php echo $row['trackingnumber'] ?>" class="modal fade" role="dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Item</th>
<th>Quantity</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<?php
$notal = DataDB::getInstance()->select_from_where('order_details','trackingnumber',$row['trackingnumber']);
foreach($notal as $rol):
$prrname = DataDB::getInstance()->get_name_from_id('product_name','product','product_id',$rol['product_id']);?>
<tr>
<td><?php echo $prrname ?></td>
<td><?php echo $rol['quantity'] ?></td>
<td><?php echo "NGN ".number_format($rol['price'], 2);?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<p></p>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
你如何獲得$行[ 'order_collective_id']出方的循環?對於每一行,您都應該在循環內編寫代碼,以便其適用於所有行。 –
目前模態被包含在循環內@ ZaidBinKhalid – nsikak
顯示你完整的代碼和平。如果您通過ID調用模型,那麼ID應該是唯一的。而且它會用唯一的行ID在循環中編寫模型。嘗試在循環內粘貼代碼而不是包含文件。 –