Return to Snippet

Revision: 49380
at July 21, 2011 00:32 by redconservatory


Initial Code
<?php 
/*
Say you created a 
TABLE named food
in the wordpress database
WITH THE COLUMNS
id
name
organic YES/NO
*/

global $wpdb; 

$query = 'SELECT id, name, organic FROM food';

$rows = $wpdb -> get_results($query);

		foreach ($rows as $key=> $value) {
			$id = $value->id;
			$name = $value->name;
			$organic = value->organic;
			?><p><?php echo $id; ?></p><?php
			?><p><?php echo $name; ?></p><?php
			?><p><?php echo $organic; ?></p><?php
		}
?>

Initial URL

                                

Initial Description
Refer to the following:
http://codex.wordpress.org/Class_Reference/wpdb

Initial Title
Wordpress: retrieve values from a custom table in the Wordpress database

Initial Tags
database, php, table, wordpress

Initial Language
PHP