I have a SQL database with the following structure and information:
idClub Pts GD
1 3 2
2 4 0
3 5 -1
4 0 -3
5 9 5
6 1 2
7 3 1
8 0 -2
9 6 0
10 7 5
If if do:
$result = $mysqli->query("SELECT * FROM table ORDER BY Pts Desc, GD Desc");
It will deliver this:
idClub Pts GD
5 9 5 //Row Number = 1
10 7 5 //Row Number = 2
9 6 0 //Row Number = 3
3 5 -1 //Row Number = 4
2 4 0 //Row Number = 5
1 3 2 //Row Number = 6
7 3 1 //Row Number = 7
6 1 2 //Row Number = 8
8 0 -2 //Row Number = 9
4 0 -3 //Row Number = 10
Each idClub has its own profile page - profile.php?Id=X - in which I need to show the club with the id but also the 2 teams that are above and below in the table.
Is there any way of knowing the row number (position) of a given value in a $result? For example, profile.php?Id=3 it will be 4; for profile.php?Id=1 it will be 6, and so on..
For instance, for profile.php?Id=3 I need a $result that delivers the following:
idClub Pts GD
10 7 5
9 6 0
3 5 -1
2 4 0
1 3 2
Thanks in advance.