我确定我昨晚发布了这个,但我找不到,我的帐户说我已经问了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>";
?>
答案 0 :(得分:0)
试试这个......
while($row = mysql_fetch_array($result)) {
$option .="<option value='". $row['tradingCounty'] . '">" . $row['tradingCounty'] . "</option>";
}
您不会在while循环中回显该选项,并且需要选项value属性。
答案 1 :(得分:0)
你能试试吗
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>";
答案 2 :(得分:0)
$result = $mysqli->query($query);
while($row = $result->fetch_array())
{
$rows[] = $row;
}
使用mysqli的上述代码语法。