繁体   English   中英

虽然循环无效

[英]while loop didnt work

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

如果您想每次在内部获取相同的行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
}

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

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

这样的事情。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM