Reputation: 4291
Trying to display results from an sql query in PHP:
SELECT *
FROM wp_celebcount
ORDER BY count DESC
I'm trying to display two columns: wp_celebcount.name
& wp_celebcount.count
Having trouble getting the result to show with PHP - I want to show this result on my index.php Wordpress theme file. Thanks for the help...
Upvotes: 3
Views: 22281
Reputation: 15456
If you're using Wordpress, it would be something like this:
global $wpdb;
$result = $wpdb->get_results('SELECT name, count FROM wp_celebcount');
foreach($result as $row) {
echo 'Name: '.$row->name.', Count: '.$row->count.'<br/>';
}
It's recommended to use the $wpdb
global as it takes care of all the database setup for you.
More information on $wpdb
can be found here.
Upvotes: 13
Reputation: 3722
Presuming you've done something like $resultSet = mysql_query('SELECT * FROM wp_celebcount ORDER BY count DESC');
You should be able to pull out the results with
while ($row = mysql_fetch_assoc($resultSet))
{
var_dump($row);
//print an element named 'name' with echo $row['name'];
}
Upvotes: 1