-4

Here is my code

$sql="SET @rank=0; SELECT * FROM (SELECT *, @rank:=@rank+1 AS Rank FROM scoregame where userid=33 order by score DESC) AS t";
$query=mysql_query($sql);
if(mysql_num_rows($query) != "")
{
  $stt=1;
  while($row=mysql_fetch_array($query))
  {
    $stt++;
    echo $row['score'];
  }
}

but something wrong:

 Warning: mysql_num_rows() expects parameter 1 to be resource
Dharman
  • 30,962
  • 25
  • 85
  • 135
Do Thanh Dat
  • 245
  • 1
  • 2
  • 10
  • 2
    Possible duplicate of [mysql\_fetch\_array()/mysql\_fetch\_assoc()/mysql\_fetch\_row() expects parameter 1 to be resource or mysqli\_result, boolean given](http://stackoverflow.com/questions/2973202/mysql-fetch-array-mysql-fetch-assoc-mysql-fetch-row-expects-parameter-1-to) – Epodax Apr 20 '16 at 09:13
  • mysql_query is returning a boolean instead of a resource, better check with [mysql_error](http://php.net/manual/en/function.mysql-error.php) – Pietro Apr 20 '16 at 09:14

1 Answers1

2

You try to run 2 queries at once. That does not work with this PHP function. But you can reduce it to one query

SELECT *, @rank:=@rank+1 AS Rank 
FROM scoregame 
cross join (select @rank := 0) r
where userid=33 
order by score DESC
juergen d
  • 201,996
  • 37
  • 293
  • 362