問題描述
我有這個代碼:
if(isset($_POST['search']))
{
$res1=mysql_query("SELECT * FROM aircraft where acode = '$_POST[ac]'") or die(mysql_error());
while($row=mysql_fetch_array($res1))
{
$airc=$row['acode'];
$amode=$row['amodel'];
$stat=$row['status'];
$rem=$row['remarks'];
echo "<center><table><form name="frmMain" method="post">
<tr><td><font face=consolas><b>Aircraft Code:</b></font></td><td><input type=text name=arc value='$airc' readonly=readonly></td></tr>
<tr><td><font face=consolas><b>Aircraft Model:*</b></font></td><td><input type=text name=am value='$amode'></td></tr>
<tr><td><font face=consolas><b>Status:*</b></font></td><td><input type=text name=st value='$stat'></td></tr>
<tr><td><font face=consolas><b>Remarks:*</b></font></td><td><input type=text name=rm value='$rem'></td></tr></table>";
}
}
在提交搜索"按鈕時,此代碼顯示飛機表中的數據.允許用戶使用 (*) 符號更新數據.
On submit 'search' button, this code displays the data from aircraft table. The user is allowed to update the data with the (*) sign.
由于狀態默認如下(可用,不可用),我改了這個
Since the Status are the following by default (Available, Not Available), I changed this
<tr><td><font face=consolas><b>Status:*</b></font></td><td><input type=text name=st value='$stat'></td></tr>
至此,
<tr><td><font face=consolas><b>Status:*</b></font></td><td><select name=st>
<option value=Available>Available</option>
<option value='Not Available'>Not Available</option>
</select></td></tr>
但我希望下拉菜單的默認值取決于$stat=$row['status'];
因為這是一個更新表單.
But I want the dropdown to have it's default value depending on
$stat=$row['status'];
since this is an update form.
如果正在檢索的數據的狀態為可用",則下拉列表的默認值應為可用".
If the data being retrieved has it's status 'Available', then the dropdown should have it's default value as 'Available'.
我怎樣才能做到這一點?我試過 <select name=status value='$stat'>
但它不起作用.任何幫助將不勝感激.謝謝!
How can I achieve that? I tried <select name=status value='$stat'>
but it doesn't work. Any help will be appreciated. Thanks!
推薦答案
只需將 selected="selected"
放在選項上,具體取決于您的 $row['status']
,
Just put selected="selected"
on the option depending on your $row['status']
,
<option selected="selected" value="available">Available</option>
這篇關于<選擇>下拉默認值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!