0

Hi Everyone,

I'm having some issues in the construction of an algorithm for a project. This is just a fraction of the algorithm and my problem is this:

I'm trying to build a PHP function that gets the values of the first and second rows of a table and subtract them. Then the function gets the second and third values and subtract them, then the third and forth and so on until the end of the table. (The table will be sorted ASC and the value of the subtraction will be use for posterior use) Is this possible?

Thank you very much. All the help provided will be helpfull

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by diafol
0

Can you provide an example of the expected operation? Does the table contain numerical values? You need to provide more details in order for someone to be able to help...

0

(The table will be sorted ASS and the value of the subtraction will be use for posterior use)

Oooh, sounds painful - do you mean like a suppository?

Anyway, post the code that you have so far.

0

I'm sorry you are right.

I have a table named position which has the columns: P_ID (int) Latitude (decimal) and Longitude (decimal).

Having for example this values applied:

Figure 1 : My table
P_ID Latitude Longitude
1 23,4 56,87
2 53,12 56,5
3 12,4 89,4
4 12,4 86,4
5 3,45 6,67

Figure 2: Ascending Latitude
P_ID Latitude Longitude
5 3,45 6,67
3 12,4 89,4
4 12,4 86,4
1 23,4 56,87
2 53,12 56,5

My goal is to order the Latitude column ascending, pick the first value of the table and the second value of the table (in my example 3,45 and 12,4). If second value minus first value is lower than let's say for example the number 5 the function searches on the Longitude table the correspondent longitude ( in my example 6,67 and 89,4 ) and does exactly the same subtraction.

Is it clear ? I guess it's a little bit confusing and I guess I'll have a place from where to start if I at least learn how to make a PHP Loop that goes through ALL rows of a column and compares the first with second, the second with third, etc...

Sorry for the mess

0

Is there any way to select just a row from a table ? Like selecting a position from an array list... where position[2] would be the second line of the table.. is that possible in php+sql ?

0

Is there any way to select just a row from a table ? Like selecting a position from an array list... where position[2] would be the second line of the table.. is that possible in php+sql ?

Yes. See the LIMIT clause. Check out the MySQL online manual:

http://dev.mysql.com/doc/

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.