What are the best practices for handling empty MySQL query results in PHP?

When executing a MySQL query in PHP, it is important to handle cases where the query returns no results. One common approach is to check if the result set is empty and handle it accordingly, such as displaying a message to the user or performing an alternative action.

// Execute the MySQL query
$result = mysqli_query($conn, "SELECT * FROM table WHERE condition");

// Check if the result set is empty
if(mysqli_num_rows($result) == 0){
    echo "No results found.";
} else {
    // Process the query results
    while($row = mysqli_fetch_assoc($result)){
        // Handle each row of data
    }
}

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