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条)

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用