填充下拉菜单不起作用 [英] populate dropdown is not working

查看:56
本文介绍了填充下拉菜单不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码填充下拉列表.我的数据库连接字符串工作正常.但由于某种原因,下拉菜单为空.

I am trying to populate the dropdown using the following code. My database connection string works fine. But the dropdown is empty for some reason.

<?  mysql_connect("localhost", "user", "pass")
                 mysql_select_db("mydatabase");  
$sql = "SELECT code1 FROM table1"; 
$result = mysql_query($sql) or die(mysql_error());
?>


 <p>  
<select name="vers">  
 <?php  
 while($row = mysql_fetch_array($result)){  
 echo "option value=\"".$row['code1']."\">".$row["code1"]."</option>";  
 }  
 ?>  
 </select>

推荐答案

好吧,开始你的 html 是无效的

Well to start with your html is invalid

echo "<option value=\"".$row['code1']."\">".$row["code1"]."</option>"; 

您缺少选项标签上的开头 <.

You're missing the opening < on the option tag.

这篇关于填充下拉菜单不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆