What best practices should be followed when iterating through database query results in a PHP while loop?

When iterating through database query results in a PHP while loop, it is important to properly fetch and process each row of data before moving to the next one. To avoid potential memory issues, it is recommended to fetch rows one at a time within the loop and free up the memory associated with each row after processing it.

// Assuming $result is the variable holding the database query results

while ($row = mysqli_fetch_assoc($result)) {
    // Process the data in $row
    // Example: echo $row['column_name'];

    // Free up memory associated with $row
    mysqli_free_result($row);
}