Note that there are some explanatory texts on larger screens.

plurals
  1. POTo have the matched value selected in populated PHP drop down list
    primarykey
    data
    text
    <p>I have managed to create populated drop down list through php taken from MySQL. Code #1</p> <pre><code>// 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-&gt;prefix . "awpcp_areas"; $query="SELECT DISTINCT area_name FROM ".$tbl_ads." WHERE area_name &lt;&gt; '' 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 .= "&lt;option value=\"" . esc_attr($savedarea) . "\"&gt;" . stripslashes($savedarea) . "&lt;/option&gt;"; } return $output; } // END FUNCTION: create a drop down list containing area options from saved area in database </code></pre> <p>then I called this function through Code #2</p> <pre><code> $allareas = create_dropdown_areanames($adcontact_country); </code></pre> <p>then I display it in the page throu Code #3</p> <pre><code>$theformbody.="&lt;select name=\"adarea\" onchange=\"changeareameo();\" id='add_new_ad_area'&gt;&lt;option value=\"\"&gt;"; $theformbody.=__("Area","AWPCP"); $theformbody.="&lt;/option&gt;$allareas&lt;/select&gt;&lt;/p&gt;"; </code></pre> <p>I want to add the code below into Code #1</p> <pre><code>$output .= "&lt;option selected='selected' value=\"" . esc_attr($savedarea) . "\"&gt;" . stripslashes($savedarea) . "&lt;/option&gt;"; </code></pre> <p>so when firing the function $allareas = create_dropdown_areanames($adcontact_country); <strong>IF</strong> the $adcontact_country variable matches with database string it would be the one selected on the drop down list and else the drop down list is generated from top to bottom. Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload