是否可以将下拉列表插入表格单元格?
谢谢!
以下是一些代码:
$sql_query="SELECT nameOfwarning FROM warnings";
$sodss=mysqli_query($d,$sql_query);
if (mysqli_num_rows($result)<1)
?>
<select name = "warnings">
<option value="Choose one of the warnings: " </option>
<?php
while ($row = mysqli_fetch_array($warnings)) {
print "<option value=";
print $row["id_warning"];
print ">" ;
print $row["warning"];
print "</option>";
}
?>
</select><br>
<?php
print "<tr><td>Insert drop down list here?: </td><td><input type=\"text\" name=\"OR HERE\"></td></tr>";
答案 0 :(得分:1)
我冒昧地也格式化你的代码。希望你不要介意。你应该这样做,以使其更具可读性。
<?php
$sql_query = "SELECT id_warning, warning FROM warnings";
$result = mysqli_query($d, $sql_query);
$dropDownHtml = '';
if (mysqli_num_rows($result) > 0) {
$dropDownHtml .= '<select name = "warnings">';
$dropDownHtml .= '<option value="Choose one of the warnings: " </option>';
while ($row = mysqli_fetch_array($result)) {
$dropDownHtml .=
'<option value="{$row["id_warning"]}">' .
$row["warning"] .
'</option>';
}
$dropDownHtml .= '</select><br>';
}
?>
<tr>
<td><?php echo $dropDownHtml; ?></td>
<td><input type=\"text\" name=\"OR HERE\"></td>
</tr>
看起来您跳过了一些代码,因为SQL查询应返回的内容与结果数组不匹配,也存在一些变量不匹配。我改变了一点看起来很可信,如果你不想在问题中发布所有代码,你应该确保你将它改回你的特定情况。