Jump to content

Calculating difference between points in array


dmhall0

Recommended Posts

I have elevation points in an array.  I need to calculate the difference between each point to get the total gain, total loss, and net.

 

Example:

point 2 - point 1 = +100

point 3 - point 2 = -10

point 4 - point 3 = -20

... and so on

 

So my outputs need to be:

Total Gain = +100

Total Loss = -30

Total Net = +70

 

Any help would be great.  I am still new to coding but this seems complicated.

Link to comment
Share on other sites

That's what I was kind of thinking. You could do the math in the query as well.

 

SELECT point 2 - point 1 AS diff2_1, point 3 - point 2 AS diff3_2, point 4 - point 3 AS diff4_3 FROM table WHERE whatever . . . 

 

Then the calculated values would be in the array produced by whichever mysql_fetch_* function you use.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.