我试图显示用户的排名,这是我当前的代码。
问题是它一直显示等级“2”。
我哪里出错?
<?
if(! defined('BASEPATH') ){ exit('Unable to view file.'); }
$sql = $db->Query("SELECT uid, SUM(`total_clicks`) AS `clicks` FROM `user_clicks` GROUP BY uid ORDER BY `clicks` DESC");
$user = $db->QueryFetchArray("SELECT uid, SUM(`total_clicks`) AS `clicks`, @rank := @rank + 1 as ranking
FROM `user_clicks`, (select @rank := 0) r
GROUP BY uid
ORDER BY `clicks` DESC");
?>
RANK # <?=$user['ranking']?>