私は私のメニューから3つの項目があります。私は異なるquantity.Butと各アイテムの合計を計算したい私のforeachループは、3つのすべての数量を1つの項目の代わりにその数量を持つすべての項目を計算しています。私が間違っていた場所を教えてください。ここに私のコードです。私のforeachループは必要以上の数を実行しています
<?php
if(isset($_POST['bill'])){
//foreach ($_POST['qty'] as $item_quantity) {
//$item_qty = $item_quantity;
//}
?>
<div class="row calc">
<div class="col-md-offset-4 col-md-4 col-md-offset-4">
<center><h4>Geektroup Hotels</h4>
<table class="table table-bordered">
<thead>
<th>Sr #</th>
<th>Item Name</th>
<th>Item Cost</th>
<th>Quantity</th>
<th>Amount</th>
</thead>
<tbody>
<?php
$count = 0;
**foreach ($_POST['item_id'] as $item_id) {
$item_num = $item_id;
foreach ($_POST['qty'] as $item_quantity) {
$item_qty = $item_quantity;**
$bill_query = "SELECT * FROM items WHERE item_id = '$item_num'";
$bill_run = mysqli_query($con,$bill_query);
if(mysqli_num_rows($bill_run)>0){
$bill_row = mysqli_fetch_array($bill_run);
$item = $bill_row['item_name'];
$item_price = $bill_row['item_cost'];
$count = $count+1;
?>
<tr>
<td><?php echo $count;?></td>
<td><p><?php echo $item;?></p></td>
<td><p><?php echo $item_price;?></p></td>
<td><p><?php echo $item_qty;?></p></td>
<td><p><?php echo $amount = $item_price * $item_qty;?></p></td>
</tr>
<?php
}
}
}
}
?>
</tbody>
</table>
</center>
</div>
</div>
</div><!-- /.container -->
私たちはあなたのフォームhtmlを見ることができますか? – Salketer
はあなたの配列構造 –
<フォームメソッド= 'POST' アクションは= ''>