mySQL查询最常见的价值。显示价值和数量

时间:2015-02-04 16:00:21

标签: php mysql

我想查询数据库以显示列中最常见的3个值(TyreMan)。然后显示值和出现次数

$sqlCommand = "SELECT TyreMan, COUNT(TyreMan) AS countTyreMan 
  FROM Pictures WHERE Tyreman IS NOT NULL AND Tyreman <> 'UNKNOWN' 
  GROUP BY TyreMan ORDER BY countTyreMan ASC LIMIT 3";
$query = mysql_query($sqlCommand) or die (mysql_error()); 
while ($row = mysql_fetch_array($query)) {
$manu = $row["TyreMan"];
echo "$manu"; 

目前我得到了

value1value2value3

我如何获得计数并像这样显示?

value1 [count], value2 [count], value3 [count]

感谢

1 个答案:

答案 0 :(得分:0)

将计数转换为字符串并将其与值连接。

$manu = $manu . $row["TyreMan"] .  '[' . $row["countTyreMan"] . ']';