-1
我有這個代碼用於填充數據庫中的條目下拉列表。它工作正常,但我想要做的是,如果我從另一個頁面向它發送一個值,它會自動選擇該值。這裏的工作代碼:自動從數據庫填充下拉列表中選擇一個值
{ $box1 = array();
$result1 = "SELECT FullName FROM UserInformation ORDER BY FullName ASC";
$rs1=odbc_exec($conn,$result1);
while($row = odbc_fetch_array($rs1)) { $box1[] = $row; }}
$FullName = '<select name="FullName" onchange="autoSubmit(); refresh()">';
$FullName .= '<option>---< Select Engineer >---</option>';
if (!empty($box1)) {
foreach ($box1 as $k => $v) {
$FullName .= '<option value="'.$v['FullName'].'">'.$v['FullName'].'</option>';}}
$FullName .= '</select>';
echo $FullName;
一種靜態下拉這樣做的方法是:
<select name="Active">
<option value="Yes" <?php if($Active == 'Yes') {echo 'selected=""';} ?>>Yes</option>
<option value="No" <?php if($Active == 'No') {echo 'selected=""';} ?>>No</option>
</select>
我說:
$test = 'James Whitley';
並試圖取代:
$FullName .= '<option value="'.$v['FullName'].'">'.$v['FullName'].'</option>';}}
隨着:
$FullName .= '<option value="'.$v['FullName'].'"' if('.$v['FullName'].' = $test){echo 'selected="selected"';} '>'.$v['FullName'].'</option>';}}
我認爲會工作,但我得到(語法錯誤,意外的T_IF)錯誤。任何幫助將不勝感激,謝謝。