我确定我昨晚发布了此内容,但我找不到它,而且我的帐户显示我已问了 0 个问题。无论如何...
我的 MySQL 数据库中有一个包含英国县的字段。我想将这些列在下拉框中,以便用户可以选择它们,以选择他们想要查看结果的英国地区。
到目前为止我已经有了......但我的下拉框显示为空?
非常感谢任何帮助。
<?php
include 'connect.php';
//set variable
$option = '';
// Get the county names from database - no duplicates
$query = "SELECT DISTINCT tradingCounty FROM offers";
// execute the query, $result will hold all of the Counties in an array
$result = mysqli_query($con,$query);
while($row = mysql_fetch_array($result)) {
$option .="<option>" . $row['tradingCounty'] . "</option>";
echo $option;
}
echo "<form id='filter' name='filter' method='post' action='resultssimple.php'>
<p><label>County</label></p>
<select name='filter' id='filter'>" . $option . "</select>
</form>";
?>
最佳答案
你可以尝试一下吗
echo "<form id='filter' name='filter' method='post' action='resultssimple.php'>
<p><label>County</label></p>
<select name='filter' id='filter'>";
// Get the county names from database - no duplicates
$query = "SELECT DISTINCT tradingCounty FROM offers";
// execute the query, $result will hold all of the Counties in an array
$result = mysqli_query($con,$query);
while($row = mysql_fetch_array($result)) {
$option .="<option>" . $row['tradingCounty'] . "</option>";
echo $option;
}
echo "</select>
</form>";
关于php - 与 mysql 数据库不同的结果作为下拉列表/php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25619292/