What is the best practice for handling error messages when a data set is not found in a MySQL database using PHP?

When a data set is not found in a MySQL database using PHP, it is best practice to check if the query returned any results and display an appropriate error message if no data is found. This can be done by using the `mysqli_num_rows()` function to determine if any rows were returned by the query. If no rows are found, an error message can be displayed to inform the user that the data set was not found.

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

// Check if any rows were returned
if(mysqli_num_rows($result) == 0) {
    echo "No data found in the database.";
} else {
    // Process the data as needed
    while($row = mysqli_fetch_assoc($result)) {
        // Do something with the data
    }
}

// Free the result set
mysqli_free_result($result);