WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

hi guys i am trying to populate a select element with options from the data in one of my sql tables heres what i have so far:

$SQL = "SELECT * FROM pt_country ORDER BY name";
    $rs = $wpdb->query($SQL);
    $nr = mysql_num_rows($rs);
        for ($i=0; $i<$nr; $i++) {
        $r = mysql_fetch_array($rs);
        echo "<OPTION VALUE=\"".$r["countrycode"]."\">".$r["country"]."</OPTION>";

im guessing quite a bit of this is wrong but to start with i cant get wordpress to return the data i just get false what am i missing here ?

share|improve this question

You should not use mysql_fetch_array()

Use wordpress built-in functions, like this:

$SQL = "SELECT * FROM pt_country ORDER BY name";
$rows = $wpdb->get_results( $SQL );
foreach($rows as $r){
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.