晚上好,我有一個問題,我正在找人幫我。通過php發送頁面後保存select的值
我有以下問題,我生成一個select
與所有選項來自數據庫,我通過一個後置動作,使用PHP發送信息。
我希望當返回到頁面時,使用select選項後,最後一個選定的值被激活到窗體。是否有可能通過JavaScript或其他方式做到這一點?
*對不起,我英文不好
$sql = "SELECT * FROM curso WHERE data = '$date'";
$result = mysql_query($sql, $conexao2);
echo "<select name=\"curso\" >";
while($linha = mysql_fetch_row($result)) {
$nome_evento = $linha[1];
$cod_evento = $linha[0];
echo "<option value=".$cod_evento.">".$nome_evento."</option>"."<br>" ;
}
echo "</select>";
你好順便說一句。你是否正在試圖將選擇框設置爲上一個選定的項目。 –
你需要做的是獲得該選定的值,並將其作爲變量傳入,然後在循環中檢查並設置「selected」值到那個匹配當前所在的那個,請參見下面的 –
mysql_ *函數已被棄用,您需要使用mysqli或PDO。 – Enstage