Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

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){
 print_r($r);
}
share|improve this answer
add comment

Your Answer

 
discard

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.