I have the following query:
$sql = "SET @rownum := 0;
SELECT * FROM (
SELECT @rownum := @rownum + 1 AS rank, totalpoints, useridFB, username
FROM user_test ORDER BY totalpoints DESC
) as result WHERE useridFB=".$uid."";
With it I'm getting the rank of a user that has earned points by playing some games in my web.
The query works great when I paste it in phpMyAdmin, I get the correct rank for the user.
What's the problem then? Well, I cannot display any data stored in the result.
I've tried the usual:
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
echo $row['totalpoints'];
echo $row['rank'];
echo $row['useridFB'];
echo $row['username'];
}
But it returns an error:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in ...
An no results printed.
What am I doing wrong? Thanks a lot!