I am looking to deliver a dropdown within the page of a WordPress Theme connecting to the backend WP Database using $wpdb and ob_start to bring through option values.
In order to do this I have had to convert mysql_fetch array to $wpdb->get results and use a Shortcode generated from a PHP Snippet plugin.
Code –
add_shortcode( 'get-city', function () {
ob_start(); ?>
<?php
global $wpdb;
$results = $wpdb->query("SELECT countryid FROM {$wpdb->prefix}city");?>
<select name="city">
<option>Select City</option>
<?php while($row=$wpdb->get_results($results)) {
echo "<option value>{$row->city}</option>";
}
echo "</select>";
return ob_get_clean();
});
The shortcode shows no errors and is able to be activated.
The dropdown shows on the page but then no options are presented for a user to select. Nothing is being brought through from the db.
I would really appreciate it if someone could point out the error.
Thanks in advance.