我需要总结所有相同的值。 我有MySQL表'成员'这些值,例如:。
name staat
--------------------
John United-states
Mary United-states
Jan Czech-republic
Paul Slovakia
Julia Slovakia
--------------------
我尝试制作一个数组
$states = array(
'United-states' => 'us',
'Czech-republic' => 'cz',
'Slovakia' => 'sk'
);
和SQL查询:
$query = mysqli_query($conn, "SELECT COUNT(*) as `count`, `staat` FROM `members` GROUP BY `staat`");
foreach (mysqli_fetch_array($query) as $item) {
${'row_'.$states[$item['staat']]} = $item['count'];
}
图表的期望结果是:
$row_us (In my example '2')
$row_cz (In my example '1')
$row_sk (In my example '2')
所有行 $ row_xx 都是动态的。