-1

我有一个在表格中显示多行的结果集,并且在其中一个表格单元格中,我添加了一个带有选项的下拉列表。表的第一行有一个正确填充 MySQL 数据的下拉列表,但在下面的行中,虽然下拉列表确实存在,但其中没有选项。谢谢!

<?php while ($expenses = mysqli_fetch_assoc($result)) { 
?>

 <tr>
 <td><?php echo number_format($expenses["amount"], 2);?></td>
 <td><?php //echo $expenses["vendor"];?></td>
 <td><?php //echo $expenses["description"];?></td>

<!-- code for type dropdown-->

<td><select>
<?php while ($row = mysqli_fetch_assoc($type_result_set)) {
?>
<option value="<?php echo $row["type_name"];?>"><?php echo $row["type_name"];?></option>
<?php
}
?>

</td>
</select>


<!-- this section resumes table after drop down-->
 <td><?php echo $expenses["department"];?></td>
 <td><input name="done" type="checkbox" id="done"></td>
 <td><textarea name="notes" id="notes"></textarea></td>
 </tr>


<?php
}
?>
4

2 回答 2

1

您的标记有错误,请确保在<select>标记之前关闭标记<td>

<td>
<select>
<?php while ($row = mysqli_fetch_assoc($type_result_set)) {?>
<option value="<?php echo $row["type_name"];?>"><?php echo $row["type_name"];?></option>
<?php}?>
</select>
</td>
于 2013-08-01T22:29:09.383 回答
1

You should put the data from $type_result_set in a array (using a while loop) before entering the $expenses = mysqli_fetch_assoc($result) loop. Once $type_result_set is looped through once, it won't give any more data, so you should store it beforehand.

于 2013-08-01T22:30:59.097 回答