0

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 ?

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);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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