看起来您正在发布arsy_sub_Code
并希望所选值保持选中状态。尝试:
echo "<select name ='sub_code' >";
$res = mysql_query("SELECT * FROM arsy_subject ORDER BY arsy_sub_Code");
if($res && mysql_num_rows($res) > 0) // PLEASE check to make sure the query worked before trying to access rows
{
while($row = mysql_fetch_assoc($res))
{
$selected = isset($_POST['sub_code']) && $_POST['sub_code'] == $row['arsy_sub_Code'] ? 'selected' : '';
echo "<option selected='$selected' value = '" .htmlentities($row['arsy_sub_Code']). "'>" .htmlentities($row['arsy_sub_Code']) . "/" .htmlentities($row['arsy_Description']) . "</option>";
}
}
echo "</select>";
编辑:
如果这是允许您编辑教授详细信息的页面,并且您希望下拉菜单显示教授的主题,那么您需要$_POST['sub_code']
用包含教授当前子代码的变量替换,所以可能类似于
$professor['sub_code']; // assuming you have selected the professor details and have stored them in an array
强制性旁注:不要在已弃用的mysql_*
库中编写新代码,使用 PDO 或 MySQLi。