从数据库中动态下拉菜单但选项值不起作用
我正在尝试创建一个动态下拉菜单,从数据库中提取城市名称(并在添加新城市时自动更新),然后在选择时转到该城市页面。下拉菜单有效,但选择城市时没有任何反应。不知道我哪里错了。这就是我得到的
<?php mysql_select_db ("db_name");
echo "<select name=database><option value='.'>Select Your City</option>";
$result = mysql_query ("select DISTINCTROW city_head from database order by city_head");
while ($city_head=mysql_fetch_assoc($database)) {
echo "<option value="#CityIDPage">".$city_head[city_head]."</option>\n"; }
echo "</select><p>";
?>
I'm trying to create a dynamic drop down menu that pulls the city name from a database (and automatically updates as I add new cities) and then when selected goes to that city page. The drop down menu works, but when selecting the city nothing happens. Not sure where I'm going wrong. Here's what I've got
<?php mysql_select_db ("db_name");
echo "<select name=database><option value='.'>Select Your City</option>";
$result = mysql_query ("select DISTINCTROW city_head from database order by city_head");
while ($city_head=mysql_fetch_assoc($database)) {
echo "<option value="#CityIDPage">".$city_head[city_head]."</option>\n"; }
echo "</select><p>";
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以添加此功能 - 将页面位置更改为所选选项的
value
值 - 通过将以下属性添加到select
:即,
请注意,您必须设置 < code>value 适合每个城市;我不知道你的数据库架构,所以我无法为你提供建议。
<select>
elements to not inherently change the page location when a new option is selected.You can add this functionality - changing the page location to the value of
value
for the selected option - by adding the following attribute toselect
:i.e.,
Note that you must set
value
appropriately for each city; I don't know your database schema, so I cannot advise you there.