Search code examples
phpmysqlcountmysql-num-rows

How to count the most common value in SQL?


At the moment I've got the following code:

$forummost = mysql_query("

 SELECT door, 
 COUNT(door) AS doorCount 
 FROM forum_posts 
 GROUP BY door 
 ORDER BY COUNT(door) 
 DESC

");
$forummostc = mysql_num_rows($forummost);
$forummostf = mysql_fetch_assoc($forummost);

Can somebody explain me why mysql_num_rows($forummost) doesn't work?

Thanks in advance!


Solution

  • GROUP BY selects only the different values of that column in mysql. In your case, as pointed out, it selects as many rows as different door values are there.