Page 1 of 2

Calculations from a database

Posted: Tue Nov 20, 2012 8:49 pm
by Thaylan

Hello

I want to use a survey in my app, and the results should be returned to the user right after completion. Everything is good so far, I can store the answers in numbers in a collection in the database. I'm having trouble calculating the results.

In my database the values in a row are something like:

username,2,4,5,3,5,4,2,4,5,1,2,3,4.

I want to do a calculation with some specific columns only (basically using sum, multiply and divide). The username I can get from a local storage, just don't know how to reference the numbers in a code. Can you help me with that?

Thanks!


Calculations from a database

Posted: Wed Nov 21, 2012 12:19 am
by maxkatz

You can do a GET on the records, you will get all the values and could then manipulate them with JavaScript.


Calculations from a database

Posted: Thu Nov 22, 2012 8:11 pm
by Thaylan

Hi Max, thanks again for the fast response. So I basically create the service, on response mapping I map all the collumns to the place I desire, and then manipulate them on the "Add JavaScript" button, right?

What's the syntax used to refer to a variable coming from the database on the JS?

Thanks!


Calculations from a database

Posted: Fri Nov 23, 2012 12:13 am
by maxkatz

The component to which you mapped will hold the value from database. One option is to use Add JavaScript -- that will be invoked during mapping. Or, once all the mappings are done, you can retrieve the values from the components and then manipulate them.


Calculations from a database

Posted: Wed Aug 07, 2013 2:05 am
by bahar.wadia

Can you please provide a detailed example to this questions.

Thanks in advance.


Calculations from a database

Posted: Wed Aug 07, 2013 2:30 am
by maxkatz

I don't have example. This is your app logic written in JavaScript. I don't know what calculations you need to do.


Calculations from a database

Posted: Wed Aug 07, 2013 2:45 am
by bahar.wadia

Do you have sample code to demonstrate how one can show a sum of all the values in a column in an app.

I am a novice at this and could use some help. I am learning by example.

Thanks in advance.


Calculations from a database

Posted: Wed Aug 07, 2013 2:53 am
by maxkatz

Save the data into an array. Then iterate over the array and add all the numbers.


Calculations from a database

Posted: Wed Aug 07, 2013 4:07 am
by bahar.wadia

Yes thank you for that.

However, can you please provide me with a sample project. I am sure have done this a million times.


Calculations from a database

Posted: Wed Aug 07, 2013 4:15 am
by bahar.wadia

I can do data manipulation with SQL. I am just not familiar with REST.