我有一个选择下拉列表,我希望有一个基于 SQL 数据的预定义选择选项。
我的sql调用:
$sel = 'SELECT threechar_currency_code, currency_name FROM currencies';
$RS = doQuery($sel);
while($row = fetchAssoc($RS)){
//The else is working, the code in the if() is what i wish to get working
/* if ($row['threechar_currency_code'] === $selected_currency){
$currencies[] = array(
'selected' => true,
'currency_code' => $row['threechar_currency_code'],
'currency_name' => $row['currency_name']
);
} else { */
$currencies[] = array(
'currency_code' => $row['threechar_currency_code'],
'currency_name' => $row['currency_name']
);
// }
}
我的选择:
<select class="mdb-select md-form" id="currency" name="currency" placeholder="Select currency" value=""
required searchable="Search here..">
<option value="none" disabled selected="selected">Currency</option>
<?php
foreach ($currencies as $c){
echo '<option value="'.$c['currency_code'].'">'.$c['currency_name'].'</option>';
}
?>
</select>
要说明的是,仅使用 else{} 就可以很好地填充所有内容,我只是希望有一个预选选项(如果它与预选值匹配)。提前致谢
墨色风雨
互换的青春