Jump to content

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.

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.

Then you're going to need to elaborate a little more, I believe. Are you trying to go through the array programatically, and just find the difference of a point and the previous point, regardless of the number of points in the array?

I am wanting to find the difference between every 2 points, just like in my first post example, then sum all the numbers > 0, sum all the numbers < 0, then give me the total.

So if there are 1000 points in the array, I would get 500 numbers.

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.