这是我的代码
$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'];
}
}
但有些不对劲:
Warning: mysql_num_rows() expects parameter 1 to be resource
非常感谢你!
答案 0 :(得分:1)
您尝试一次运行2个查询。这不适用于这个PHP函数。但您可以将其缩减为一个查询
SELECT *, @rank:=@rank+1 AS Rank
FROM scoregame
cross join (select @rank := 0) r
where userid=33
order by score DESC