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.

1 Answer 1


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");
    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 and acknowledge you have read our privacy policy.

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