Page 1 of 1

Showing the sum values from a database column in a label

Posted: Thu Apr 03, 2014 10:55 am
by Paul Medawar

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"?


Showing the sum values from a database column in a label

Posted: Thu Apr 03, 2014 1:10 pm
by Kateryna Grynko

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


Showing the sum values from a database column in a label

Posted: Tue Jul 21, 2015 5:02 am
by Jack Bua

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.


Showing the sum values from a database column in a label

Posted: Tue Jul 21, 2015 11:54 pm
by Jack Bua

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

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