doujiazong0322 2017-02-01 08:09
浏览 10

如何保存下拉选定的值。 位于表格列中的下拉列表,如图所示

I want to save each row by getting the ID of selected value in the dropdown like this:

Like This

  • 写回答

1条回答 默认 最新

  • dongzouh51192 2017-02-01 08:30
    关注

    This is supposed to be a comment, but i have a low reputation here Hi Khan i do not really understand what you mean. A dropdown is basically a select option. The attribute "value" is what gets posted as the selected value. To save the value, simply have this:

    $selected_value = mysqli_real_escape_string($connection, $_POST['name_of_dropdown_from_html_form']);
    

    To get the value on an update form, do this:

    <select id="id_of_field" name="name_of_field" class="form-control">
        <?php
        #i assume your select dropdown list is from a database. 
        #SO in that table, we have two columns, id_of_table and list_type. 
        #For example a list of different types of cars,
        #id(1) and list_type(BMW).
        #SO now we check if the id of the car is in the current dropdown list
        $list = $class->get_list();
    
        foreach ($list as $key => $value) {
            if ($value['id_of_table'] == $value['list_type']) {
                $selected = "selected='selected'";
                echo "<option value=\"{$value['id_of_table']}\" {$selected}>{$value['list_type']}</option>";
            } else {
                echo "<option value=\"{$value['id_of_table']}\">{$value['list_type']}</option>";
            }
        }
        ?>
    </select>
    

    try and integrate this with your project and let me know what you get

    评论

报告相同问题?

悬赏问题

  • ¥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文件加载里面的的资源