如果发现匹配,我正在尝试在列表中显示所选值。它已成功填充,但所选值代码未运行。
Code:
$StaffName = 'Jimmy Chan';
<select name="Staff" id="Staff"><?php
$data = array();
$data[0] = '';
echo "<option value='" . $data[0] . "'>" . $data[0] . "</option>";
$result= $DB->query('select No, FirstName, LastName from Staff');
foreach ($result as $data)
{
$SNo = $data['No'];
$SFN = $data['FirstName'];
$SLN = $data['LastName'];
$SName = $SFN.' '.$SLN;
if($SName == $StaffName)
{
echo "<option value='".$Sno."' selected = \"selected\">".$Sname."</option>\n";
}
else
{
echo "<option value='" .$SNo. "'>" . $SName . " </option>";
}
}
?>
</select>
第二个 else 语句确实运行,但不是 if 语句。我已经把“选定”放在里面了。好心提醒。