creating dropdown from db
-
I am trying to create a form with a dropdown box populated with DB items. I have created a shortcode that works cause I can get an empty dropdown to appear on my page but filling it with DB items doesn’t work.
yes, my query works because I have tested it and there are 2 results.
I have tried both echo and return.Any help is appreciated.
$results = $wpdb->get_results(“SELECT term_id, name FROM testterms WHERE term_id >= 3″);
$output = ‘<select name=”mycategories”>’;
$output = $output . ‘<option value=””></option>’;
foreach($results as $row){
$output = $output . ‘<option value=”‘ . $row[“term_id”] . ‘”>’ . $row[“name”] . ‘</option>’;
}
return ($output . ‘</select>’);
The topic ‘creating dropdown from db’ is closed to new replies.