对于这里的新手问题提前表示抱歉。。。
我目前的第一个值是禁用和默认的"选择"选项,然后在进行选择时更改为所选选项。
但是,如果用户在没有重新选择的情况下再次提交,则该值将默认返回,因为帖子为空。因此,如果是的话,有没有办法使用以前的值?
<select name="test_select" style="width: 110px">
<option disabled="disabled" selected="selected">
<?php
if(!empty($_POST['test_select'])){
echo $_POST[test_select'];}
else
echo "Select Option"; ?>
</option>
<?php $sql = mysql_query("SELECT test FROM test_settings");
while ($row = mysql_fetch_array($sql)){
?><option><?php echo $row['test']; ?></option><?php }?>
</select>
提前感谢
Dan
我想问题是表单没有发送禁用的值。
我会编辑代码如下:
<select name="test_select" style="width: 110px">
<?php
if (empty($_POST['test_select']))
echo '<option selected="selected">Select Option</option>';
$sql = mysql_query("SELECT test FROM test_settings");
while ($row = mysql_fetch_array($sql)){
$selected = isset($_POST['test_select']) && $row['test'] == $_POST['test_select']
? ' selected="selected"'
: '';
echo '<option'.$selected.'>'.$row['test'].'</option>';
?>
</select>