1

大家好,我正在尝试执行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>
4

2 回答 2

0

如果您想每次都在内部获得相同的行,while则必须重置 mysqli 结果集的内部指针。为此,您可以使用mysqli_data_seek()

你最终会得到这样的东西:

while ($row = mysqli_fetch_array($result)) {
    // snip ...
    while ($row2 = mysqli_fetch_array($result2)) {
        // snip
    }
    mysqli_data_seek($result2, 0);
    // snip
}
于 2012-11-11T11:44:48.667 回答
0

还请确保<select>具有唯一的名称,否则您的所有状态都将被错误地捕获。

<select name="change_<?=$row['row_id']?>">

类似的东西。

于 2013-12-16T08:55:15.750 回答