I'm very new to php and I hope this thread doesn't get locked aswell. I'm making a highscore table that will display my users in order of highest points. I've entered a query which seems to work, but the question still remains, where should I put it to display the information on a php page? I've tried putting it in a td table in <?php but it just shows an empty table.
Code:
SELECT
ID, username, points,
@prev := @curr,
@curr := points,
@rank := IF(@prev = @curr, @rank, @rank+1) AS rank
FROM
users,
(SELECT @curr := null, @prev := null, @rank := 0) sel1
ORDER BY points DESC
;
Thanks for any help!
of course, the php coding of it would be:
Code:
$sql = 'SELECT'
. ' ID, username, points,'
. ' @prev := @curr,'
. ' @curr := points,'
. ' @rank := IF(@prev = @curr, @rank, @rank+1) AS rank'
. ' FROM'
. ' users,'
. ' (SELECT @curr := null, @prev := null, @rank := 0) sel1'
. ' ORDER BY points DESC'
. ' ; LIMIT 0, 30 ';
Last edited by moltar; 04-03-2010 at 12:29 PM..
|