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
error77Asked:
Who is Participating?
 
Jason C. LevineConnect With a Mentor No 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.