ADDING UP THE TOTAL VALUE OF ALL 'COST' FIELDS - Oct 13th, 2011


User s2smedia had a field called 'cost' and wanted to add up all of the 'cost' fields and give a TOTAL

Jason Sauchuk from Interactive Tools offered the following for CMSB Version 2.08 and above:


<?php
$totalCost = 0.00;
$listings = mysql_select('listings');

foreach (
$listings as $listing) {
$totalCost += floatval($listing['cost']);
}

?>


And this for previous CMSB versions:


<?php
$totalCost = 0.00;

$tableName = "listings";
$listings = mysql_query_fetch_all_assoc("SELECT * FROM `{$TABLE_PREFIX}$tableName`");

foreach (
$listings as $listing) {
$totalCost += floatval($listing['cost']);
}

?>



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service