What is the best way to handle the scenario where no values are found in the database query and output a specific message in PHP?

When no values are found in a database query, it is important to handle this scenario gracefully by checking if any rows are returned and outputting a specific message if no rows are found. One way to achieve this is by using the `mysqli_num_rows()` function to check the number of rows returned by the query and then displaying a message if the count is zero.

// Perform database query
$query = "SELECT * FROM table_name WHERE condition";
$result = mysqli_query($connection, $query);

// Check if any rows are returned
if(mysqli_num_rows($result) == 0) {
    echo "No results found.";
} else {
    // Process the results
    while($row = mysqli_fetch_assoc($result)) {
        // Output the data
    }
}

// Free result set
mysqli_free_result($result);