我无法将下拉菜单设置为粘性(以便在第一次提交表单后,将在下一页的表单中预先选择所选择的选项)。我删除了一些我认为不相关的代码。我尝试将值设为 $_GET['continent'] 但这没有用。有人有想法吗?见函数 createpulldown
<!DOCTYPE html>
<head>
<title>Homework 14</title>
</head>
<body>
<?php
if (isset($_GET['submitted']))
handleform($_GET['country']);
displayform("country");
?>
</body>
function displayform($menuname) {
echo "<fieldset><legend>Select a continent and I will show you information from the CIA about it.</legend>
<form method = 'get'>";
createpulldown($menuname);
echo "<input type='submit' name='submitted' value='Search'>
</form>
</fieldset>";
}
function createpulldown($menuname) {
echo "<select name='$menuname'>";
$dbc = connectToDB();
$query = "SELECT Continent FROM countries GROUP BY Continent";
$result = performQuery($dbc, $query);
while ($row=mysqli_fetch_array($result, MYSQLI_ASSOC)){
$continent = $row['Continent'];
if (isset($_GET[$menuname]))
echo "<option name='continent' value = $continent selected>$continent</option>\n";
else
echo "<option name='continent' value = $continent>$continent</option>\n";
}
echo "</select>";
disconnectFromDB($dbc, $result);
}
?>