Table: cm_rank
|id|rankpoeng|tittel |
-----------------------
|1 | 0 |Sivil |
|2 | 322 |Wannabe|
|3 | 1450 |Hitman |
我要做的是:
$currentXp = 500;
$query = mysql_query("SELECT * FROM cm_rank WHERE $currentXp > rankpoeng LIMIT 1");
while ($rows = mysql_fetch_array($query)):
$levelTitle = $rows['title'];
echo $levelTitle;
endwhile;
$levelTitle
变量应该只包含文本“Wannabe”,因为用户的xp比它所需要的多,但对于下一个排名来说不够。我如何构造这样的查询?
最佳答案
您应该按rankpoeng列排序以获取最高的有效值。
$query = mysql_query("SELECT * FROM cm_rank WHERE $currentXp > rankpoeng ORDER BY rankpoeng DESC LIMIT 1");
关于php - MySQL查询:最近<查询结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30209881/