I'm using Wordpress(last)
I try to Echo SUM(feed)
from SQL table in the archive loop where all posts of specific category shown
<section category="category1">
...
<?php get_template_part( 'entry_category' ); ?>
<?php endwhile; endif; ?>
</section>
In my entry_category
i've got basic HTML tags to output an article and my function to echo SUM(feed)
<article>...
<?php bankTotal(the_title);?>
</article>
And here is the function in my function.php
function bankTotal($bank_name){
global $wpdb;
$result = $wpdb->get_results($wpdb->prepare("SELECT SUM(feed) FROM feeds_table WHERE bank_name='$bank_name'"));
print_r($result);
I understand that I Need to $_POST
$bank_name to a function.
But is there a way to do so WITHOUT $_POST
? Something like bankTotal($bank_name)
I'l need to show SUM(feed)
for each <Article>...</article>
of a <section>
Is there a way to pass the $bank_name
to a function without using ajax($_POST['bank_name'];
)?
SQL table looks like this:
bank_name | segment_name | feed |
---------------------------------
bank-A | segmentB | 12 |
bank-A | segmentC | 2 |
.................................
bank-X | segmentA | 32 |
***SOLVED(thanks to Seti) UPD: If you are trying to ECHO
out SUM(row)
do it like this
function bankTotal($bank_name){
global $wpdb;
$result = $wpdb->get_results($wpdb->prepare("SELECT SUM(feed) AS someTotal FROM feeds_table WHERE bank_name='$bank_name'", ARRAY_N));
foreach($result as $row){
echo "$row->someTotal";
}
}