duan198727
2013-05-29 18:28
浏览 95
已采纳

下拉菜单包含来自MySQL数据库的数据作为选项

i try to get data from mysql db into html dropdown , i execute the query in PHPmyadmin and its work fine , the result is one record,and all the website is connected with theses details of MYSQL my code is :

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

the output is drop-down with one empty record , any one can help me in that ?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题