2015-02-24 164 views
0

這裏是code.Please幫助我的例子。MySQL查詢mysql_num_rows不工作

$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

嘗試在做ROW_NUMBER()功能的其他方式。見下圖:

$query=mysql_query("SELECT @row_count:[email protected]_count+1 AS rank, * FROM users, (SELECT @row_count:=0) AS A WHERE username='$username'"); 
$numrows=mysql_num_rows($query); 
0

只需使用:

$query=mysql_query("SELECT * , count(*) as rank FROM users WHERE username='$username' "); 
$numrows=mysql_num_rows($query); 
+0

我們還需要顯示等級。@ noob – 2015-02-24 05:33:47

+0

@vamsikr這裏的等級是什麼,只是查詢返回的行數是多少? – 2015-02-24 05:34:43

+0

是的,但我們需要顯示排名的最終數組。 – 2015-02-24 05:36:42