MySQLから取得したphpを使用して、データが入力されたドロップダウンリストを作成できました。コード#1
// START FUNCTION: create a drop down list containing area options from saved area in database
function create_dropdown_areanames() {
global $wpdb;
$output = '';
$tbl_ads = $wpdb->prefix . "awpcp_areas";
$query="SELECT DISTINCT area_name FROM ".$tbl_ads." WHERE area_name <> '' ORDER by area_name ASC";
$res = awpcp_query($query, __LINE__);
$listofsavedareas = array();
while ($rsrow=mysql_fetch_row($res)) {
$listofsavedareas[] = $rsrow[0];
}
$savedareaslist = $listofsavedareas;
foreach ($savedareaslist as $savedarea) {
$output .= "<option value=\"" . esc_attr($savedarea) . "\">" . stripslashes($savedarea) . "</option>";
}
return $output;
}
// END FUNCTION: create a drop down list containing area options from saved area in database
次に、コード#2でこの関数を呼び出しました
$allareas = create_dropdown_areanames($adcontact_country);
次に、コード #3 を介してページに表示します
$theformbody.="<select name=\"adarea\" onchange=\"changeareameo();\" id='add_new_ad_area'><option value=\"\">";
$theformbody.=__("Area","AWPCP");
$theformbody.="</option>$allareas</select></p>";
以下のコードをコード #1 に追加したい
$output .= "<option selected='selected' value=\"" . esc_attr($savedarea) . "\">" . stripslashes($savedarea) . "</option>";
そのため、関数 $allareas = create_dropdown_areanames($adcontact_country); を起動するとき。$ adcontact_country変数がデータベース文字列と一致する場合、それがドロップダウン リストで選択されたものになり、そうでない場合、ドロップダウン リストは上から下に生成されます。前もって感謝します