嘗試從mysql獲取值到<select>
標記。
我用while while循環&從2個不同的表中獲取數據。
我已經嘗試了給定的代碼,但無法獲取數據。
請幫忙!將MySql數據取回到<select>
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
// Connect to server and select databse.
$conn=mysqli_connect($host,$username,$password) or die("cannot connect");
mysqli_select_db($conn,$db_name);
$result = mysqli_query($conn,"SELECT * from dummy");
$uresult=mysqli_query($conn,"SELECT name from user where role='Support'");
$uname=array();
while ($rows=mysqli_fetch_array($uresult))
{
$uname[]=$rows['name'];
}
echo "<table border='1' width='100%' >
<tr><th colspan='7' ><h2 align='center'>Details</h2></th></tr>
<tr bgcolor='grey'>
<th width='10%' class='text-center'>Emp No.</th>
<th width='15%' class='text-center'>Name</th>
<th width='30%' class='text-center'>Task</th>
<th width='20%' class='text-center'>Assigned To</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td align='center'>" . $row['emp_no']. "</td>";
echo "<td align='center'>" . $row['emp_name']. "</td>";
echo "<td align='center'>" . $row['task'] . "</td>";
echo "<td align='center'> <select name='select1'> <?php while ($rows=mysqli_fetch_array($uresult)) { ?><option><?php echo $rows['name'];?> </option><?php } ?> </select> </td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
?>
錯誤: 解析錯誤:語法錯誤,意想不到 ''(T_ENCAPSED_AND_WHITESPACE),期望標識符(T_STRING)或可變(T_VARIABLE)或數字(T_NUM_STRING)
你想呼應的<?PHP語法中的PHP代碼。非常差的編碼。回聲「
你爲什麼要嘗試兩次獲取它?你已經把它放在你的容器裏了 – Ghost
這段代碼中有很多紅旗,我不知道從哪裏開始。請多閱讀一下PHP手冊。我想寫一個詳細的答案,但後來我意識到它不會幫助你,因爲你還不熟悉基本的語言語法,我不能在這裏教你所有的東西。 –