PHP Ajax下拉框

时间:2014-12-04 13:12:13

标签: php ajax database

<?php
require ("init.php");

?>
<head>
<script src="ajax.js"></script>
<script src="common.js"></script>
</head>
<body>
<?php
$query = "SELECT * FROM User1";
$result = mysqli_query($connection, $query);
echo '<form> ';
echo "Select a Users:"; 
echo '<select name="users" onchange="showUser(this.value)">';
while ($row=mysqli_fetch_assoc($result)){
    echo $row=['Username'];
    echo '<option value="'.$row=['Username'].'">'.$row=['Username'].'</option>';
}
echo '</select></form>';
?>

<div id="txtHint"><b>User info will be listed here.</b></div>

</body>

我遇到的问题是下拉框只显示多次数组并且没有显示我的数据库中的用户名,但是我的数据库的连接正常,因为尝试调试时它只能回显一个用户名

2 个答案:

答案 0 :(得分:1)

IT应该是这样的:

while ($row=mysqli_fetch_assoc($result)){
    //echo $row=['Username']; //Invalied here
    echo '<option value="'.$row['Username'].'">'.$row['Username'].'</option>';
}

无需=签名。

答案 1 :(得分:0)

正确:

echo $row=['Username'];// This is unnecessary.
echo '<option value="'.$row=['Username'].'">'.$row=['Username'].'</option>';// what is = doing here?

要:

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