doukangbin9698 2014-09-29 10:13
浏览 34
已采纳

如何从下拉列表中选择后获取数据

I want to fetch data from dropdown list. Like if I choose employee id 40 from the dropdown list it will fetch the data from database of that employee and will shown in the textboxes.

this is my dropdown code. please help me how can i get the selected value.

<?php
    $con=mysqli_connect("localhost","root","","hct_db");
    // Check connection
    if (mysqli_connect_errno()) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
?>

 <label>Select Employee ID</label>
     <select class="form-control" name="employee_id">
         <?php 
         $result = mysqli_query($con,"SELECT employee_id FROM employee order by employee_id");

         while($row = mysqli_fetch_array($result)) 
             echo "<option value='" . $row['employee_id'] . "'>" . $row['employee_id'] . "</option>";
         ?>
     </select>
  • 写回答

5条回答 默认 最新

  • doutiaosu2310 2014-09-29 10:21
    关注

    To get your selected value, you have to reach the $_GET or $_POST supertables after the user submits the form.

    So, after the submit, get it as, if you POST:

    <?php 
    $employee_id = $_POST['employee_id']; ?>
    

    If you GET:

    <?php 
    $employee_id = $_GET['employee_id']; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源