Thaylan
Posts: 0
Joined: Wed Nov 14, 2012 9:45 pm

Calculations from a database

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!

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Calculations from a database

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

Thaylan
Posts: 0
Joined: Wed Nov 14, 2012 9:45 pm

Calculations from a database

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!

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Calculations from a database

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.

bahar.wadia
Posts: 0
Joined: Wed Aug 07, 2013 2:05 am

Calculations from a database

Can you please provide a detailed example to this questions.

Thanks in advance.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Calculations from a database

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

bahar.wadia
Posts: 0
Joined: Wed Aug 07, 2013 2:05 am

Calculations from a database

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Calculations from a database

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

bahar.wadia
Posts: 0
Joined: Wed Aug 07, 2013 2:05 am

Calculations from a database

Yes thank you for that.

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

bahar.wadia
Posts: 0
Joined: Wed Aug 07, 2013 2:05 am

Calculations from a database

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

Return to “Issues”