What I am trying to do is select * from table then get the count of duplicate rows in a column but also have another column (make) associated with the results.
Eg:
Desired output:
Make Model Qty
Ford Focus 3
Ford Fiesta 5
Ford Mondeo 1
BMW M3 1
Audi A4 2
Audi A3 4
Current output:
Model Qty
Focus 3
Fiesta 5
Mondeo 1
M3 1
A4 2
A3 4
My code:
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$modelArray = [];
foreach ($rows as $row) {
$modelArray[] = $row['model'];
}
$result = array_count_values($modelArray);
foreach ($result as $model=>$qty) {
echo $model." ".$qty;
}
I don't know how to also include the 'make' column in my results using the array_count_values() function.
I think I may be going about this the wrong way as it would appear to be a fairly common task but I can't find any information on how to do it like this.
Any help would be greatly appreciated thanks.