When I used this code, the result/echo display as I wanted.
<?php
$user_checks = $wpdb->get_results(
"
SELECT ID, user_nicename
FROM $wpdb->users
"
);
foreach ( $user_checks as $user_check )
{
echo $user_check->ID;
echo $user_check->user_nicename;
}
?>
But when I choose table other then what wordpress provide e.g:
<?php
$user_checks = $wpdb->get_results(
"
SELECT id, name
FROM $wpdb->uap_banners
"
);
foreach ( $user_checks as $user_check )
{
echo $user_check->id;
echo $user_check->name;
}
?>
The Result is blank… Did I miss something? (I’m new on wordpress)
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
$wpdb does not contain any reference to custom tables. So the uap_banners property doesn’t exist. You need to write in the table name the say way it was written when creating the table. So in your case that would probably be (assuming you included the database prefix):
$user_checks = $wpdb->get_results(
"
SELECT id, name
FROM {$wpdb->prefix}uap_banners
"
);
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0