Populate custom meta box from database
-
I want to populate a series of checkboxes from a database table that I have filled with values myself, i.e. it’s not a wordpress table, but in the same database.
This is what I have done in the none wordpress parts of my site, that works perfectly
$query = "SELECT genre_id, genre_name FROM genres ORDER BY genre_name ASC"; $result = mysqli_query ($dbc, $query) or trigger_error ("query: $query\n<br />MySQL Error: " . mysqli_error($dbc)); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo '<div class="genre_checkbox"><input type="checkbox" name="genre[]" value="' . $row['genre_name'] . '">' . $row['genre_name'] . '</div>'; }However, this doesn’t work in wordpress of course.
This is what I have so far:
add_action("admin_init", "genre_fields"); function genre_fields(){ add_meta_box('event_genres', 'Genres', "event_genre_options", "event", "normal"); } function event_genre_options(){ global $post; global $wpdb; include(EVENT_CALENDAR_DIR . "event_class.php"); $event = new Manage_events; $data = $event->get_event($post->ID); $rows = $wpdb->get_results( "SELECT genre_id, genre_name FROM genres ORDER BY genre_name ASC", ARRAY_A); while ($rows = mysql_fetch_array($result, MYSQLI_ASSOC)) { echo '<div class="genre_checkbox"><input type="checkbox" name="genre[]" value="' . $row['genre_name'] . '">' . $row['genre_name'] . '</div>'; } }As you can see I’m much more familiar with standard PHP and mySQL syntax and I can’t find what I need in the reference for WP.
Any help would be hugely appreciate.
Thankyou
And i’m getting:
mysql_fetch_array() expects parameter 1 to be resource, null given
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Populate custom meta box from database’ is closed to new replies.