How can we retrieve the highest result for each person on a specific date in PHP?
To retrieve the highest result for each person on a specific date in PHP, we can use a SQL query to group the results by person and date, then select the maximum result for each group. We can achieve this by using the GROUP BY clause in the SQL query along with the MAX() function to get the highest result for each person on a specific date.
<?php
// Assuming we have a database connection established
$date = '2022-01-01'; // Specific date for which we want to retrieve the highest result
$sql = "SELECT person, MAX(result) AS highest_result
FROM results
WHERE date = '$date'
GROUP BY person";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "Person: " . $row['person'] . " - Highest Result: " . $row['highest_result'] . "<br>";
}
} else {
echo "No results found for the specified date.";
}
mysqli_close($conn);
?>