2014-12-04 85 views
0
<?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> 

我遇到的問題是,在下拉框中僅顯示陣列多次,沒有顯示從我的數據庫的用戶名然而,我的數據庫連接是否正常工作tryed當作爲調試它得到了它呼應了只有一個用戶名PHP的Ajax下拉框

回答

1

IT應該是這樣的:

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

沒有必要說=跡象。

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>'; 
+0

'$行= [ '用戶名']'這是分配一個數組$行變量。 – vaso123 2014-12-04 13:17:04

+0

'$ row = ['Username']'在這裏不正確。 – 2014-12-04 13:17:09