Sum from column in database

joeriFranck 20 Feb, 2018
Let me say I write items to a database. That works fine!

For example is save to database:

columns: name - cat1 - cat2 - cat3

cat1 cat2 and cat3 are all integers

I want to display the sum of each column to the site.
Can that be done, I found helpitems for this from 2010 but they don't work anymore.


Kind regards
Max_admin 21 Feb, 2018
Hi Joeri,

You will need to use a "Read data" action and in the "Field to retrieve" box use:
SUM(cat1):cat1_sum
Then you can extract the result using a shortcode, if your "Select type" is set to "first matching" then you need something like this:
{var:read_data_name.Model_name.cat1_sum}
Best regards
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 21 Feb, 2018
Hi joeriFranck ,

It's not simple to sum values in the same row using MySQL so probably the best solution is to use a Custom Code or PHP action after you load the data, calculate the total and add it to your form data as a new entry.

Bob
joeriFranck 21 Feb, 2018
@admin: i did this:

Sum from column in database image 1

and then this:
Sum from column in database image 2

That doens't work in frontend there is no result.

At greyhead, only the columns is good for me
Max_admin 05 Mar, 2018
Hi joeriFranck,

The "read_data_name" in your case is "read_data11"

Best regards
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
joeriFranck 05 Mar, 2018
with <p style="text-align: center;">{var:read_data11.totaalcat1.cat1_sum} --</p>
it doens't work either
joeriFranck 26 Mar, 2018
I need this now for another form to but have still no clue
joeriFranck 04 May, 2018
It's been more than a month now ?? Somebody?
GreyHead 05 May, 2018
Hi JoeriFranck,

You said that the column names were cat1, . . . but in one of your images you have SUM(_catagorie1) . . . is that correct? It would be unusual to have a column name starting with an underscore?

Bob
healyhatman 05 May, 2018
model.field1:field1
model.field2:field2
model.field3:field3
(model.field + model.field2 + model.field3):model.alias
This topic is locked and no more replies can be posted.