That is in my theme’s capabilities.php. I’ve an exterior MySQL database that I am connecting to in WordPress with the next code, and I am trying to create a shortcode that exhibits the full of a column named total_downloads
, with rows filtered by one other column utm_campaign
. The desk identify is reports_downloads
. So, line 3 of my code returns the string “apple” and I wish to get the sum of total_downloads
for apple.
The issue is that this outputs Array ( )
on the web page as a substitute of a readable quantity. I am battling PHP and extra so with DB queries, however I am making an attempt to be taught. Any steering on easy methods to get this operate to return the integer 2?
utm_campaign | total_downloads |
---|---|
apple | 1 |
orange | 1 |
apple | 1 |
operate getAllDownloads() {
$wpdb2 = new WPDB( 'db_user', 'db_pass', 'db_name', 'db_host');
$utm = do_shortcode('[wpmem_field utm_campaign]');
$end result = $wpdb2->get_results("SELECT SUM(total_downloads) as result_value FROM reports_downloads WHERE utm_campaign = ".$utm."");
print_r($end result);
echo $end result[0]->result_value;
}
add_shortcode('b3_all_downloads', 'getAllDownloads');