• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

Wordpress - Echo records from an SQL Query

Hi all,

I am using this code to create a query on wordpress:

<?php $wpdb->query('select * from myTable'); ?>

Now, how do I get it to echo the results?

From example:

echo $id;
echo $myfield;

etc from the results?

THanks
0
error77
Asked:
error77
1 Solution
 
Jason C. LevineNo oneCommented:
You'll probably want to use get_results(), optionally with output types:

http://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results

$yourstuff = $wpdb->get_results('select * from myTable');

foreach ($yourstuff as $yourstuff) {
        echo $id;
        echo $myfield;
}

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now