Summary and Stats

okkhalid

New Member
Hello,
I'm working on non for profit database, and trying to figure out how I can do this:
I have created all the elements that I need and some of the elements I set calculation into it.
But I want to create a page/link called: Summary and Stats.
when someone click on that, will see sum of different fields for example:

Family Size: 200
Number of Children: 50
Number of Female: 120
Number of Male: 80

So the numbers above as just an example to show the total of children ... etc.

here is my element names.

Full Element Name: sdb___Family_Size
Full Element Name: sdb___No_Children
Full Element Name: sdb___Female
Full Element Name: sdb__Male

Please help to create a page to show only the stats.

Thank you so much.
summar.PNG
 
There's nothing built in to do that, but it's easy to do with a little custom code using something like Sourcerer (from noNumber) embedded in an article or module.

So to get the sum of family size and children ...

Code:
{source}<?php
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery->select('SUM(Family_Size) AS sum_family')->from('sdb');
$myDb->setQuery($myQuery);
$sumFamily = $myDb->loadResult();
echo "<div>Total Family Size: " . $sumFamily . "</div>";
$myQuery->clear()->select('SUM(No_Children) AS sum_children')->from('sdb');
$myDb->setQuery($myQuery);
$sumChildren = $myDb->loadResult();
echo "<div>Number of Children: " . $sumChildren . "</div>";
?>
{/source}

You could probably get all the stats in one query, but if you aren't that familiar with MySQL, probably easier to do each one seperately.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top