我没有写这个代码,它来自Racetracker(http://sourceforge.net/projects/racetracker/),但我一直试图做一些修改。
我正在尝试制作一个简短的球队积分榜,因此将其限制为5支球队。团队排名页面中有“ORDER BY SUM(driverpoints)
”,但它没有做任何事情(该页面使用Javascript手动排序HTML表格)。此外,当我尝试添加LIMIT 5时,它同样什么都不做,它只是打印所有不同的团队。这是相关的代码(我在这里删除了很多重复的OR,因为有43个OR drivername
='$ thenames [1]'限定符,它们不影响ORDER BY和LIMIT部分是否工作):
$total= mysql_query("SELECT SUM(driverpoints), SUM(events), SUM(firstplace),
SUM(qual1stplace), SUM(lapsseason), SUM(lapsledseason), SUM(top5season),
SUM(top10season), SUM(provisionals)
FROM `$whatseriestable`
WHERE `year` = $siteyear AND `drivername` = '$thenames[0]'
OR `drivername` = '$thenames[1]'
ORDER BY `SUM(driverpoints)` DESC LIMIT 5");
令人费解的是,ORDER BY和LIMIT在车手排行榜摘要中表现良好:
$stn= mysql_query("SELECT * FROM `$whatseriestable`
WHERE `year` = $siteyear
ORDER BY `driverpoints` DESC LIMIT 10");
为什么这不符合团队排名?
答案 0 :(得分:2)
它可能只是你的WHERE子句...而且是对这个左右的预测
WHERE
`year` = $siteyear
AND `drivername` = '$thenames[0]'
OR `drivername` = '$thenames[1]'
被解释为
WHERE
( year condition and first driver condition )
OR ( second driver )
我认为你的意思是
WHERE
( year condition )
and ( first driver condition OR second driver )
将你的司机条件包裹在()parens中。