What is the best way to handle displaying a message when no entries are found in a MySQL database using PHP?

When no entries are found in a MySQL database using PHP, you can handle it by checking the number of rows returned from the query. If the number of rows is 0, display a message indicating that no entries were found. This can be achieved by using an if statement to check the row count and then echoing out the message.

// Perform a query to retrieve data from the database
$query = "SELECT * FROM table_name";
$result = mysqli_query($connection, $query);

// Check if any rows were returned
if(mysqli_num_rows($result) == 0) {
    echo "No entries found in the database.";
} else {
    // Display the data from the database
    while($row = mysqli_fetch_assoc($result)) {
        // Display the data here
    }
}