2013-04-27 38 views
0

你好我是試圖獲得與此代碼的位置:如何獲取用戶在mysql中的排名位置?

$sql = mysql_query("SELECT @rownum:[email protected]+1 AS posicao, nome, pontos FROM ranking u, (SELECT @rownum:=0) r ORDER BY pontos DESC"); 

它的工作原理,但我希望某個特定用戶的位置,我用這個代碼:

$sql = mysql_query("SELECT @rownum:[email protected]+1 AS posicao, nome, pontos FROM ranking u, (SELECT @rownum:=0) r WHERE pontos=100 ORDER BY pontos DESC"); 

但只返回一個記錄,我無法得到這個位置,因爲它總是1!

有人幫我嗎?謝謝

回答

0

嘗試

SELECT * FROM 
(SELECT @rownum:[email protected]+1 AS posicao, nome, pontos 
FROM ranking u, (SELECT @rownum:=0) r 
ORDER BY pontos DESC 
) as a 
WHERE pontos = 100 
;