Php 嵌套,而表格选择仅给出一个结果
我试图从MySQL查询中获取一个下拉列表的项目列表,并在另一个列表中显示信息,而这会延迟表中的每一行 当我不使用第二个while,但添加第一个select时,它会起作用。第一个select具有我期望的结果,但以下行为空Php 嵌套,而表格选择仅给出一个结果,php,html,mysql,Php,Html,Mysql,我试图从MySQL查询中获取一个下拉列表的项目列表,并在另一个列表中显示信息,而这会延迟表中的每一行 当我不使用第二个while,但添加第一个select时,它会起作用。第一个select具有我期望的结果,但以下行为空 <table style="width:100%"> <tr> <td>Type</td> <td>Qty</td> <td>Temp(°
<table style="width:100%">
<tr>
<td>Type</td>
<td>Qty</td>
<td>Temp(°C)</td>
<td>From</td>
<td>To</td>
</tr>
<tr>
<?php
if ($order_search->num_rows > 0) {
// output data of each row
while ($detail = mysqli_fetch_array($order_search)) {
echo "<td>";
echo "<select name='type'>";
while ($row = mysqli_fetch_row($item_search)) {
echo "<option>";
echo $row[0];
echo "</option>";
}
echo "</select>";
echo "</td>";
echo "<td>$detail[1]</td>";
if ($detail[2] > 0) {
echo "<td>$detail[2]°C</td>";
} else {
echo "<td>$detail[2]N/A</td>";
}
echo "<td>$detail[3]</td>";
echo "<td>$detail[4]</td>";
echo "</tr>";
}
}
?>
<tr>
<td>
<form method="post">
<input type="hidden" name="entry_id" value="<?php echo $entry_id; ?>">
<input type='hidden' name='order_id' value="<?php echo $order_id;?>">
<input type="submit" name="add_equipment" value="Add Equipment">
</form>
</td>
</tr>
</table>
类型
数量
温度(摄氏度)
从…起
到
外部,而不是以任何方式“刷新”结果;因此,当第二次迭代发生时,$item_搜索结果将已经用完
如果您需要多次使用结果中的行,它们应该存储在一个数组中,您可以重复迭代。可能的重复与我刚才回答的相同。我必须对此进行阅读,但它是否仍然适用于两个不同的查询?我试着把数据搜索放在第二个while之前,对吗?是的,在它之前、中间或之后。如果您将其倒回第0行,则其中任何一个都应该有效。也许可以在下面提供一个更新的代码示例,显示您是如何添加它的。谢谢Devon,它工作得很好。
<table style="width:100%">
<tr>
<td>Type</td>
<td>Qty</td>
<td>Temp(°C)</td>
<td>From</td>
<td>To</td>
</tr>
<tr>
<?php
if ($order_search->num_rows > 0) {
// output data of each row
while ($detail = mysqli_fetch_array($order_search)) {
echo "<td>";
echo "<select name='type'>";
while ($row = mysqli_fetch_row($item_search)) {
echo "<option>";
echo $row[0];
echo "</option>";
}
mysqli_data_seek($item_search,0);
echo "</select>";
echo "</td>";
echo "<td>$detail[1]</td>";
if ($detail[2] > 0) {
echo "<td>$detail[2]°C</td>";
} else {
echo "<td>$detail[2]N/A</td>";
}
echo "<td>$detail[3]</td>";
echo "<td>$detail[4]</td>";
echo "</tr>";
}
}
?>
<tr>
<td>
<form method="post">
<input type="hidden" name="entry_id" value="<?php echo $entry_id; ?>">
<input type='hidden' name='order_id' value="<?php echo $order_id;?>">
<input type="submit" name="add_equipment" value="Add Equipment">
</form>
</td>
</tr>
</table>