1

I have created a table named ic_states i want to make a select box from the database values using wpdb. I have tried wpdb::get_row but not getting the result. It is showing only value. Can someone help me. I have checked the question if anyone asked before but i didn't found any suitable query for my problem.

0

You can used below code to get results from the database in wordpress.

global $wpdb, $posts;
$prefix = $wpdb->prefix;
$query = $wpdb->get_results("SELECT * FROM {$prefix}states");
if($query){
    echo '<select><option value="select">Select</option>';
    foreach ($query as $value) {
      echo '<option value="'.$value->ID.'">'.$value->ID.'</option>';
    }
    echo "</select>";
}

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.