There is a database with a user table, in which the rsite column displays information from which site the users came from. trying to conclude the number of sites from which the user came, it turned out:

 $dbh = mysql_connect($host, $user, $pswd) or die("Не могу соединиться с MySQL."); mysql_select_db($database) or die("Не подключаюсь."); $query = mysql_query("SELECT rsite, COUNT(rsite) AS cnt FROM user GROUP BY rsite asc"); echo "<caption>Количество регистраций с сайтов:</caption>"; while ($row = mysql_fetch_array($query)){ echo "<table><tr><td>".$row['rsite']." - ".$row['cnt']."</td></tr></table>"; } 

here the name of the site is displayed and through the dash the number in the table with the ordering alphabetically "rsite asc", i.e.

  • asite - 3
  • bsite - 1
  • csite - 10

and how to make ordering by quantity, i.e.

  • bsite - 1
  • asite - 3
  • csite - 10

thanks for the answer

  • add to request order by COUNT(rsite) - Mike
  • If I add this: $ query = mysql_query ("SELECT rsite, order by COUNT (rsite) AS cnt FROM user GROUP BY rsite asc"); , nothing is displayed, empty - Roman
  • read basic information on the sql language. ru.wikipedia.org/wiki/ORDER_BY_(SQL) order by is written at the end of the request - Mike

1 answer 1

 SELECT `rsite`, COUNT(`rsite`) AS `cnt` FROM `user` GROUP BY `rsite` ASC ORDER BY `cnt` ASC 
  • thanks, it out - Roman