以下是示例代码。请帮助我。
$query=mysql_query("set @row_count=0;SELECT *,@row_count := @row_count+1 as rank FROM users WHERE username='$username' ");
$numrows=mysql_num_rows($query);
答案 0 :(得分:0)
只需使用:
$query=mysql_query("SELECT * , count(*) as rank FROM users WHERE username='$username' ");
$numrows=mysql_num_rows($query);
答案 1 :(得分:0)
在执行ROW_NUMBER()
功能时尝试另一种方式。见下文:
$query=mysql_query("SELECT @row_count:=@row_count+1 AS rank, * FROM users, (SELECT @row_count:=0) AS A WHERE username='$username'");
$numrows=mysql_num_rows($query);