How can multiple events on the same day be displayed in a PHP MySQL query result?

When displaying multiple events on the same day in a PHP MySQL query result, you can group the events by the date and then display them together. One way to achieve this is by using the GROUP BY clause in your MySQL query to group the events by the date column. Then, in your PHP code, you can iterate over the query result and display the events for each date.

// MySQL query to select events grouped by date
$query = "SELECT date, event_name FROM events_table GROUP BY date";

$result = mysqli_query($connection, $query);

if(mysqli_num_rows($result) > 0) {
    while($row = mysqli_fetch_assoc($result)) {
        echo "<h2>" . $row['date'] . "</h2>";
        
        // Display all events for the current date
        $eventsQuery = "SELECT event_name FROM events_table WHERE date = '" . $row['date'] . "'";
        $eventsResult = mysqli_query($connection, $eventsQuery);
        
        if(mysqli_num_rows($eventsResult) > 0) {
            while($eventRow = mysqli_fetch_assoc($eventsResult)) {
                echo "<p>" . $eventRow['event_name'] . "</p>";
            }
        }
    }
} else {
    echo "No events found.";
}