Title: creating dropdown from db
Last modified: February 1, 2021

---

# creating dropdown from db

 *  [larryse69](https://wordpress.org/support/users/larryse69/)
 * (@larryse69)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/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>’);

Viewing 1 replies (of 1 total)

 *  [Yordan Soares](https://wordpress.org/support/users/yordansoares/)
 * (@yordansoares)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/creating-dropdown-from-db/#post-14005650)
 * Hello [@larryse69](https://wordpress.org/support/users/larryse69/),
 * This code snippet can help you achieve this: [Create radiobuttons with custom post type](https://wordpress.org/support/topic/create-radiobuttons-with-custom-post-type/#post-13854395).
 * P.S.: This isn’t an exact solution, you need to adapt it to your particular case.
 * Best regards,
    Yordan.

Viewing 1 replies (of 1 total)

The topic ‘creating dropdown from db’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Yordan Soares](https://wordpress.org/support/users/yordansoares/)
 * Last activity: [5 years, 4 months ago](https://wordpress.org/support/topic/creating-dropdown-from-db/#post-14005650)
 * Status: not resolved