【发布时间】:2014-01-04 20:14:45
【问题描述】:
我有一个具有以下结构和信息的 SQL 数据库:
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
如果这样做:
$result = $mysqli->query("SELECT * FROM table ORDER BY Pts Desc, GD 描述");
它将提供这个:
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
每个 idClub 都有自己的个人资料页面 - profile.php?Id=X - 我需要在其中显示带有 id 的俱乐部以及表格中上下两支球队。
有没有办法知道 $result 中给定值的行号(位置)? 例如,profile.php?Id=3 它将是 4;对于 profile.php?Id=1 它将是 6,依此类推..
例如,对于 profile.php?Id=3,我需要一个提供以下内容的 $result:
idClub Pts GD
10 7 5
9 6 0
3 5 -1
2 4 0
1 3 2
提前致谢。
【问题讨论】: