What are the limitations of using GROUP BY in PHP when trying to group data based on multiple criteria?
When using GROUP BY in PHP to group data based on multiple criteria, the limitation is that you can only group by one column at a time. To overcome this limitation, you can concatenate the columns you want to group by into a single column using CONCAT function in your SQL query.
$sql = "SELECT CONCAT(column1, '-', column2) AS grouped_column, COUNT(*) AS count
FROM table_name
GROUP BY grouped_column";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "Grouped Column: " . $row['grouped_column'] . " - Count: " . $row['count'] . "<br>";
}
} else {
echo "0 results";
}