$myrows will be an array. You can dump it out with print_r($myrows) to see what is in it.
Your query is not coded correctly. The word ‘OBJECT’ should not be inside the quotes.
Besides that, unless ‘hotels’ is a table that you created outside of WordPress, there will not be a table by that name. Please explain what you are trying to do so the proper query can be determined.
Especially explain if ‘hotels’ is a Category, a Custom Post type, or something else.
To print things from the array, you use a foreach loop, something like this:
$myrows = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'parks'", OBJECT);
//print_r($myrows);
global $post;
foreach ( $myrows as $post ) {
setup_postdata($post);
echo "<p>TITLE:"; the_title(); echo "</p>";
}
Thank you for your reply. I really appreciate it.
Okay So I have a list of hotels in the area in the database in a table called hotels.
I want to be able to call out the hotels that are in the table and display them on a wordpress page.
Each hotel has an id, name, address, cost and picture. I want to display it in a table format too.
Thanks again.
I can’t test this as I have no ‘hotels’ table in my test database, so it may require some changes.
$myrows = $wpdb->get_results( 'SELECT * FROM hotels', OBJECT);
//print_r($myrows);
if ($myrows) {
foreach ( $myrows as $hotel ) {
echo "<p>ID:$hotel->id NAME:$hotel->name COST:$hotel->cost</p>";
}
}
I leave the formatting of the output up to you.
If you don’t get any output, uncomment the print_r() line to see if you are getting any results.
Thank you so much, You are an absolutely angel. Its works fantastically.