What are some best practices for handling MySQL result resources in PHP to avoid errors like the one mentioned in the warning message?

When handling MySQL result resources in PHP, it's important to properly free up the resources after you're done using them to avoid memory leaks and potential errors. One common error is trying to access the data in a result resource after it has been freed, which can lead to warnings like "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given". To avoid this, make sure to free the result resource using mysqli_free_result() after fetching the data.

// Query the database
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);

// Fetch data from the result resource
while ($row = mysqli_fetch_array($result)) {
    // Process the data
}

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