weixin_33681778 2014-12-04 13:12 采纳率: 0%
浏览 10

PHP Ajax下拉框

<?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>

the problem i am having is that the drop down box only shows array multiple times and does not show usernames from my database however the connection to my database is working as when tryed debugging it got it to echo out just one username

  • 写回答

2条回答 默认 最新

  • Memor.の 2014-12-04 13:14
    关注

    IT should be like this:

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

    No need that =sign.

    评论

报告相同问题?