Displaying a Total from a Table Column

4 posts by 3 authors in: Forums > CMS Builder
Last Post: October 29, 2009   (RSS)

By (Deleted User) - October 27, 2009 - edited: October 27, 2009

I am tring to figure out how to create a Total Column

If I have a Table called servers and then column called number_boxes

I want to be get a code to take all the numbers in that number_boxes column and display the total.

And what do i have to put in the above call for PHP for it to work?

I know it was this

<?php SELECT SUM(weight) AS total FROM `weight_management`;?>

But do not know how to incorporate that with CMSBuilder

Re: [ross] Displaying a Total from a Table Column

By (Deleted User) - October 28, 2009

I tried that and it gave me either Blank Answer or Notice: Undefined variable: total in

Re: [hegadmin] Displaying a Total from a Table Column

By Dave - October 29, 2009

Without seeing the viewer file it's hard to know what the problem might be.

If you know MySQL, though, you can use that directly. When you load the viewer_functions.php file it automatically connects to the CMSB database for you. So you can then just call mysql_query() and other functions as needed.

Or you can use a CMSB database function to return the first record like this:

require_once "cmsAdmin/lib/viewer_functions.php"; // update to match your server path
list($total) = mysql_query_fetch_row_array(" SELECT SUM(weight) AS total FROM `cms_weight_management`");
print "Total: $total";

Make sure you have a recent version of CMSB and that you replace cms_ with your CMSB table prefix.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com