我使用下面给出的代码填充表格列中的某些值。它只是填补空白..
你能找到它的问题吗?
<select name="category">
<option value="" selected>Select a category</option>
<?php
mysql_connect("localhost","root","");
mysql_select_db("muskilaasaan");
$category = "SELECT cat FROM category";
$query_result = mysql_query($category);
while($result = mysql_fetch_array($query_result))
{
?>
<option value = "<?php echo $result['cat']?>"/>
<?php
}
?>
</select>
答案 0 :(得分:1)
<select name="category">
<option value="" selected>Select a category</option>
<?php
mysql_connect("localhost","root","");
mysql_select_db("muskilaasaan");
$category = "SELECT cat FROM category";
$query_result = mysql_query($category);
while($result = mysql_fetch_assoc($query_result))
{
?>
<option value = "<?php echo $result['cat']?>"><?php echo $result['cat']?></option>
<?php
}
?>
</select>
更改为mysql_fetch_assoc,并且您没有在选项标记中添加任何内容,这会导致它显示为空白。
答案 1 :(得分:0)
如果在mysql_select_db()中将连接字符串指定为第二个参数,它会没有用?请看这里的示例:http://php.net/manual/de/function.mysql-select-db.php