What are some potential solutions for counting unique team entries in a database table for each race in PHP?

To count unique team entries in a database table for each race in PHP, you can use SQL queries to group the entries by race and count the distinct team entries. One approach is to use a SQL query with the COUNT and DISTINCT functions to achieve this.

// Connect to the database
$pdo = new PDO("mysql:host=localhost;dbname=your_database", "username", "password");

// Query to count unique team entries for each race
$sql = "SELECT race_id, COUNT(DISTINCT team_id) AS unique_teams FROM entries GROUP BY race_id";

// Execute the query
$stmt = $pdo->query($sql);

// Fetch the results
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

// Output the results
foreach ($results as $result) {
    echo "Race ID: " . $result['race_id'] . " - Unique Teams: " . $result['unique_teams'] . "<br>";
}