我試圖從MySQL數據庫的數據轉換成HTML下拉列表中,我執行在phpMyAdmin和做工精細的查詢,結果是一個記錄,並且所有的網站與論文連接MYSQL的細節我的代碼是:與MySQL的DATEBASE作爲選項的數據下拉菜單
<?php
mysql_connect("localhost", "root", "1212") or die("Connection Failed");
mysql_select_db("test")or die("Connection Failed");
$query = "SELECT department_name FROM department";
$result = mysql_query($query);
?>
<label for="department" > Department Name </label>
<select name="departments" >
<?php
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<option value="<?php echo $line['field'];?>"> <?php echo $line['field'];?> </option>
<?php
}
?>
</select>
輸出與一個空的記錄下拉,任何一個能幫助我嗎?
閱讀: http://stackoverflow.com/questions/10009464/fetching-data-from-mysql-database-to-html-dropdown-list 這: HTTP://計算器。 com/questions/7430536/mysql-database-making-drop-down-menu-using-data-already-entered-in-html -php –