$id = $row['id'];
通过$_POST
语句,然后获取每个$_POST
变量,然后通过foreach
打印它们。
提前致谢!
order.php:
foreach ($rows as $row) {
$food = $row["food"];
$price = $row["price"];
$picture = $row["picture"];
$id = $row['id'];
echo "<tr>
<td><img src='$picture' width='120px' /></td>
<td>$food</td>
<td>$$price</td>
<td><input type='number' min='0' max='10' placeholder='#' name='$id' maxlength='1'></td>
</tr>";
}
action.php的:
foreach ($rows as $row){
$food = $row['food'];
$price = $row['price'];
$id = $row['id'];
if(isset($_POST[$id])){
$qty = $_POST[$id];
echo 'set';
echo $qty;
}else{
echo 'unset';
$qty = '';
}
echo "<tr>
<td>$food</td>
<td>$qty</td>
<td>$price</td>
</tr>";
}
答案 0 :(得分:1)
将你的回声改为:
echo "<tr>
<td><img src='$picture' width='120px' /></td>
<td>$food</td>
<td>$$price</td>
<td><input type='number' min='0' max='10' placeholder='#' name='qty[".$id."]' maxlength='1'></td>
</tr>";
然后在你的action.php中:
foreach ($rows as $row){
$food = $row['food'];
$price = $row['price'];
$id = $row['id'];
if(isset($_POST['qty'][$id])){
$qty = $_POST['qty'][$id];
echo 'set';
echo $qty;
}else{
echo 'unset';
$qty = '';
}
echo "<tr>
<td>$food</td>
<td>$qty</td>
<td>$price</td>
</tr>";
}