打开编辑页面时,在列表中选择数据默认chossen

时间:2015-05-24 19:07:47

标签: php mysql

我希望将数据库中的选定数据作为默认值

回显

(如果用户在他想要编辑他的数据时在注册中选择了国家美国,则该列表选择美国作为默认值,如果他想选择另一个国家并更改他的第一个选择,他可以这样做)

<select id="exam_ch" name="exam_ch" class="select_list_exams">
    <?php
        $sql="SELECT * FROM `exam` WHERE `avilable` = 1 " ;
        $result=$ conn->query($sql);
        while($row = $result->fetch_assoc()) {
            echo "<option value=".$row['id'].">"
                . $row['date']." The Time"
                . $row['time']."</option>";
        }
    ?>
</select>

2 个答案:

答案 0 :(得分:0)

In the option tag, before it closes, add a if statement to check if $row["id"] equals to the selected value of the user, if so, echo out selected.

For example, an option tag for usa with id 1 where the selected id by user is 1 should be: usa

答案 1 :(得分:0)

如果您要匹配的行是提交的u

,您可以执行此类操作
id