I have created a table called ccc_campaigns in my database and I am retrieving the data with the following statement:
global $wpdb;
$campaign_list = $wpdb->get_results(
'SELECT *
FROM ccc_campaigns
ORDER BY id DESC');
This works as expected on my local and on one of my servers, the data is displayed doing:
foreach ($campaign_list as $campaign)
But in the server where this wordpress is supposed to be, the query comes back empty. I can't understand or find a reason why it is failing on that server.
Any ideas?
Thank you so much
Make sure the database prefix are the same.
EDIT: I guess you are building some kind of plugin, so just to make sure, db prefix is not causing any errors, use this function instead.
function getCampaignResults(){
global $wpdb;
$table_name = $wpdb->prefix . "campaigns";
$active_rows = $wpdb->get_results(
"SELECT * FROM {$table_name}"
);
foreach ($active_rows as $active_row){
echo $active_row->the_title;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.