Forums

how to total the data in one field ?

dedyisn 21 Feb, 2011
Hello there

I have a dropdown field. it's value are Open, Progress and Close.
I want there is a sum from the record in database, so the data will come out like :

Open Problem = 3
Progress Problem = 22
Close Problem = 5

How to make it's happen ?

Thanks for your help
dedyisn 21 Feb, 2011
I have 30 recorded data in database, there are 1 field that contain number on it's data
How to sum(total) the data from the field and show in on the frontpage ?


Example :

ID | data1 | data 2 |
1 | 50 | 32 |
2 | 23 | 34 |
3 | 56 | 12 |

Total 129 | 68

Thanks🙂
GreyHead 21 Feb, 2011
Hi dedyisn,

The simplest way to do this is to add a MySQL query into the ChronoConnectivity footer box to return the total values you need.

Bob

PS This is also the answer to your other post about totals so I've merged the two topics.
dedyisn 22 Feb, 2011
Thanks for your response
but i'm new in php and mysql coding, can you show me some example of this query ?

Thanks
GreyHead 22 Feb, 2011
Hi dedyisn,

Here's a simple example, you can find more from the MySQL documentation.
$db =& JFactory::getDBO();
$query = "
    SELECT SUM(`data1`) AS `total_data1`
        FROM `#__some_table_name`;
";
$db->setQuery($query);
$total_data1 = $db->loadResult();
echo "Total Data 1 = ".$total_data1;
?>


Bob
This topic is locked and no more replies can be posted.