How can PHP be used to automatically refresh a webpage with updated database entries?

To automatically refresh a webpage with updated database entries using PHP, you can implement a solution where the webpage periodically makes AJAX requests to check for new data in the database. When new data is detected, the webpage can be refreshed to display the updated information to the user.

<?php
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);

// Check for new data in the database
$query = "SELECT * FROM table WHERE updated_at > NOW() - INTERVAL 1 MINUTE";
$result = $conn->query($query);

if ($result->num_rows > 0) {
    // New data found, trigger page refresh
    echo '<script>location.reload();</script>';
}
?>