如何在提交表单后保留动态下拉框选项
<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>
答案 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>';