我正在尝试创建一个粘性下拉选项框。但每次单击“提交”按钮时,该值都不会延续。它改变。
我做错了什么?
<select name=person >
<option value="NULL">Choose a person</option>';
<?php $dbc = getDBC ();
$result = $dbc->query('SELECT * from person');
while ($row = $result->fetch_assoc()) {
echo "<option value=\"$row[ID]\"";
if (isset($_POST['person']) && ($_POST['person'] == $row[ID])) {
echo 'selected="selected"';
}
echo ">($row[ID])   $row[FIRST_NAME]   $row[LAST_NAME]</option>\n";
}
?>
</select>
答案 0 :(得分:0)
尝试以下代码我做了一些语法更改更改。您还可以使用条件SELECT * from person where id = $_POST['person']
<select name=person >
<option value="NULL">Choose a person</option>';
<?php
$dbc = getDBC ();
$result = $dbc->query('SELECT * from person');
while ($row = $result->fetch_assoc()) {
echo "<option value=\"$row['ID']\"";
if (isset($_POST['person']) && $_POST['person'] == $row['ID']) {
echo 'selected="selected"';
}
echo ">($row['ID'])   $row['FIRST_NAME']   $row['LAST_NAME']</option>\n";
}
?>
</select>