【发布时间】:2012-11-11 11:33:48
【问题描述】:
大家好,我正在尝试执行 while 循环。
while 循环将遍历所有订单。 它可以工作,但不知何故它不会在订单状态中循环。 例如,订单 4 状态为待处理,但订单 5 状态未显示任何内容。 我怀疑我把括号放错了。
这是我的代码。
<form action="results-action" method="post" enctype="multipart/form-data">
<fieldset>
<table width="600" border="1">
<tr><td><h2>Pending Order</h2></td></tr>
<tr>
<th scope="col">Order ID</th>
<th scope="col">Name</th>
<th scope="col">Address</th>
<th scope="col">Product Name</th>
<th scope="col">Produt Quantity</th>
<th scope="col">Price</th>
<th scope="col">Order status</th>
</tr>
<?php
while ($row = mysqli_fetch_array($result)) {
?>
<tr>
<td><input type="text" value='<?=$row['virtuemart_order_id']?>' name="orderid" id="virtuemart_order_id"></td>
<td><?=$row['first_name']?></td>
<td><?=$row['address_1']?></td>
<td><?=$row['order_item_name']?></td>
<td><?=$row['product_quantity']?></td>
<td><?=$row['product_final_price'] ?></td>
<td><select name="change">
<?php
while ($row2 = mysqli_fetch_array($result2)) {
?>
<option value="<?=$row2['order_status_code'] ?>"><?=$row2['order_status_name'] ?></option>
<?php
} //end inner while
?>
</td>
</tr>
<?php
} //end outer while
?>
</table>
</fieldset>
<fieldset>
<table>
<tr>
<td><input type="submit" value="Update status" name="update status"> </td>
</tr>
</table>
</fieldset>
</form>
【问题讨论】:
-
$result和$result2是什么?如果您不以某种方式重置$result2,我看不出内部while怎么会运行不止一次。 -
顺便说一句你没有结束
<select> -
也是一个建议。使用
join,因为在我看来,这可以通过一个查询来完成。
标签: php loops while-loop