Adding together all entries of a database field

3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 2, 2009   (RSS)

By dwellingproductions - March 31, 2009

Hello! Hopefully there's a fairly straight-forward way to do this.

I have a multi-record where each record contains member information. One of these items is a "point" value made up of only numbers. (The administrator assigns points to each member based on merit.) I am currently displaying each individual member's point value on their member page.

What my client now wants is for all the points of every member to be added together (to show an organizational, or group, total) and then have that result (total) also displayed on each member's individual page.

How would I go about doing this? Thanks, in advance, for any assistance!

Jeremy
---------------------------

Dwelling Productions

www.dwellingproductions.com

Re: [ross] Adding together all entries of a database field

By dwellingproductions - April 2, 2009

Ross,

Once again, thanks so much! That's exactly what I needed. I ended up creating a page with HTML on it just so I could test it on the server while I was working with it. Then, I just included the page itself, instead of the variable only.

In case anyone is interested, here's the code for the page

--------------------------------------------------------------------------

<?php
require_once "/home/content/p/h/c/phchurch/html/cmsAdmin/lib/viewer_functions.php";

list($membersRecords, $membersMetaData) = getRecords(array(
'tableName' => 'members',
'loadUploads' => '0',
'allowSearch' => '0',
));

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>

<?php $totalScore = 0;?>

<?php foreach ($membersRecords as $record):?>
<?php $record['totalPoints'];?>
<?php $totalScore += $record['totalPoints'];?>
<?php endforeach;?>

<?php if (!$membersRecords):?>
0
<?php endif; ?>


<?php echo number_format($totalScore); ?>

</body>
</html>

--------------------------------------------------------------------------

Then, to include the page: <?php include 'totalScore.php'; ?>

--------------------------------------------------------------------------

Thanks again! - Jeremy
---------------------------

Dwelling Productions

www.dwellingproductions.com