提交表单后如何保留动态下拉框选项

时间:2017-03-14 07:05:57

标签: php html

如何在提交表单后保留动态下拉框选项

<select name="sector_id" id="country" class="input-block-level" style="background-color: #EAF0F5;" >
            <option value=""><font size='7' face='arabic typesetting' color='red'>chose</font></option>
            <?php
            if($rowCount > 0){
                while($row = $query->fetch_assoc()){

                    echo '<option value="'.$row['sector_id'].'">'.$row['sector_name'].'</option>';
                }
            }else{
                echo '<option value="">not available</option>';
            }
            ?>
        </select>

1 个答案:

答案 0 :(得分:0)

变化

 echo '<option value="'.$row['sector_id'].'">'.$row['sector_name'].'</option>';

 echo '<option value="'.$row['sector_id'].'"'.($row['sector_id']==$_POST['sector_id'] ? '  selected="selected"' : '').'>'.$row['sector_name'].'</option>';