在php中提交值后保留数据库下拉列表的值?

时间:2018-04-18 20:20:40

标签: php mysql submit-button

以下是我用于动态显示下拉列表的代码。但是我发布后无法保留下拉列表的值?我能够插入值并能够保留textboxes的值。但是无法保留下拉列表

            可用的医生

            <?php 
            $selectedDoctor = $_POST["doctortype"];
            $sql = "select firstname from users where userid in (select userid from doctortype where doctortype = \"$selectedDoctor\");";
            include_once("inc_databaseClass.php");
            $dClass=new databaseClass;
            $results=$dClass->connect();
            $result = mysqli_query($results,$sql);
            echo "<select name = 'selectDoctors' id = 'idaname'>"; 
            echo "<option value = ''>";

            while ($row = mysqli_fetch_array($result)) {

            $selected = (isset($_POST['selectDoctors']) && $_POST['selectDoctors'] == $row['firstname']) ? 'selected = "selected"' :'';
            ?>
            <option <?php echo $selected; ?> value = "<?php echo $row['firstname']; ?>"> <?php echo $row['firstname']; ?> </option>
            <?php } ?>
            </select>

        </p>

0 个答案:

没有答案