我在这里按照上一个问题获得了一个链接到MySQL的下拉菜单。它的工作方式没有表格,只有形式,所有room_id
只是散布在一条线上而不是进入下拉框。关于如何修复它的任何想法?谢谢
//Creates a form for room_id
echo "<form action=''>";
echo "<select name='room_id'>";
//Creates drop down box to show the current rooms vacant
$sql = "SELECT * FROM room";
$sql.= " WHERE room_vacant = 1";
$stmt = $dbh->query($sql);
echo "<select name='room_id'>";
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<option value='" . $row['room_id'] . "'>" . $row['room_id'] . "</option>";
} //Closes drop down box
echo "</select>";
//Submit button
echo "<input type='submit' value='Submit'>";
//Closes form
echo "</form>";
答案 0 :(得分:3)
原因是你正在回复你的选择两次。删除一个。
//Creates a form for room_id
echo "<form action=''>";
echo "<select name='room_id'>";
//Creates drop down box to show the current rooms vacant
$sql = "SELECT * FROM room";
$sql.= " WHERE room_vacant = 1";
$stmt = $dbh->query($sql);
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<option value='" . $row['room_id'] . "'>" . $row['room_id'] . "</option>";
} //Closes drop down box
echo "</select>";
//Submit button
echo "<input type='submit' value='Submit'>";
//Closes form
echo "</form>";