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
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>";
}
-
1