Paul Medawar
Posts: 0
Joined: Thu Apr 03, 2014 10:55 am

Showing the sum values from a database column in a label

Hi...I have a database called "cash" set up with a column called "cashvalue".

Can anyone help me with the javascript I need to write to calculate the sum of all the values in this column and store it in a localstorage called "_cash"?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Showing the sum values from a database column in a label

Hi Paul,

You can get a service result on service Success event using a variable 'data'. Than walk through the array and count the sum https://api.jquery.com/jQuery.each/
prevar arr = data._cash;
var sum = 0;
$.each( arr, function( key, value ) {
sum += value;
});/pre

Jack Bua
Posts: 0
Joined: Sun Jun 28, 2015 10:16 pm

Showing the sum values from a database column in a label

Hi Kateryna,

I think you are real close to solving my issue . i have a collection "jobs" and want to sum up all the "price" values that my list service returns (it is filtered but that works). I want to put the result into "ttl_price" on my page. I cant quite figure out how to do this with this code though.

Jack Bua
Posts: 0
Joined: Sun Jun 28, 2015 10:16 pm

Showing the sum values from a database column in a label

Nevermind, I figured it out with fresh pot of coffee and a few hours.

https://getsatisfaction.com/apperyio/...

Return to “Issues”