我有以下代码生成下拉列表。我希望选择的值是另一个页面上相同下拉列表的默认值。我用来生成下拉列表的代码是area_index.php
:
// Write out our query.
$query = "SELECT * FROM hub";
// Execute it, or return the error message if there's a problem.
$result = mysql_query($query) or die(mysql_error());
$dropdown = "<select name='hub'>";
while($row = mysql_fetch_assoc($result)) {
$dropdown .= "\r\n<option value='{$row['name']}'>{$row['name']}</option>";
}
$dropdown .= "\r\n</select>";
?>
<form method="post" align= "right">
<table >
<tr>
<td>Select the Hub for which you want to add and area: </td>
<td><?php echo $dropdown; ?></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Add" align= "right" /></td>
</tr>
</table>
我想在我的页面中显示相同的下拉列表,area_view.php
但下拉列表的默认值必须等于所选值。
使用的变量area_index.php
是 $hub_name = $_POST['hub'];