I’m trying to group same rows and count them. So far I managed to group them but I want to count them too. I mean output the number as well.
Now the output look like this: Jane
but I want something like this: Jane (14)
<?php
$sql = ' SELECT firs_name, GROUP_CONCAT(first_name) as id FROM people GROUP BY first_name ORDER BY count(id) DESC';
foreach ($db->query($sql) as $row) {
echo '<tr><td> '.$row['first_name'].' </td> </tr>';
}
?>
I copy pasted your solution and this is what I get.
Parse error: syntax error, unexpected ‘(’ in C:\xampp\htdocs\tartalomkezelo\admin\index.php on line 137
<?php
$sql = ' SELECT CONCAT(first_name, ' (', COUNT(*), ') ') FROM people GROUP BY first_name ORDER BY COUNT(*) DESC';
foreach ($db->query($sql) as $row) {
echo '<tr><td> '.$row['first_name'].' </td> </tr>';
}
?>