你好我用数据库中的数据填充了一个下拉列表,现在我想检索所选的值并回显它但它没有工作,它一直空着。
<select>
<option value="0">--None Selected--</option>
<?php
$dbhost = 'localhost';
$dbuser = 'Phil';
$dbpass = '********';
// Fetching UserGroupID int TextBox
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
$sql = "SELECT * FROM usergroups";
mysql_select_db('dopetunez');
$result = mysql_query($sql);
// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
// then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_assoc($result)){
?>
<option value="<?php echo $row["UserGroupID"] ?>"> <?php echo $row["UserGroup"]?>
</option>
<?php
}
?>
</select>
答案 0 :(得分:1)
$sql = "SELECT * FROM usergroups";
mysql_select_db('dopetunez');
与
mysql_select_db('dopetunez');
$sql = "SELECT * FROM usergroups";
答案 1 :(得分:0)
您应首先选择数据库。然后只有您可以访问查询。请改变这样,
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db('dopetunez');
$sql = "SELECT * FROM usergroups";