我有这个代码,我遇到的问题是,一旦我选择一个选项并保存它将不记得下次选择。但是帖子已经在数据库中注册了正确的值。是否有引起您注意的语法错误?谢谢你的帮助。
平台:PHP,SQLite
<tr>
<?php
//location
?>
<td class='tdt' class='tdt'><?php te("Department");?>:</td>
<td>
<select id='locations' name='locations'>
<option value=''><?php te("Select");?></option>
<?php
foreach ($locations as $key=>$location ) {
$dbid=$location['id'];
$itype=$location['name'];
$s="";
if (($locations=="$dbid")) $s=" SELECTED ";
echo " <option $s value='$dbid'>$itype</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
答案 0 :(得分:0)
你可以试试这个(假设你准备了$locations
数组)
<select id='locations' name='locations'>
<option value=''><?php te("Select");?></option>
<?php
foreach ($locations as $key => $location ) {
$s = $_POST['locations'] == $location['id'] ? 'selected' : '';
echo "<option $s value='" . $location['id'] . "'>" . $location['name'] . "</option>";
}
?>
</select>