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?

Who is Participating?
Jason C. LevineConnect With a Mentor No oneCommented:
You'll probably want to use get_results(), optionally with output types:


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

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

Open in new window

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.