What are some best practices for efficiently outputting the results of a MySQL query in PHP?
When outputting the results of a MySQL query in PHP, it is important to use efficient methods to minimize memory usage and improve performance. One best practice is to fetch the results row by row using a loop, rather than fetching all the results at once. This can be achieved by using functions like `mysqli_fetch_assoc()` or `mysqli_fetch_array()` to fetch each row individually.
// Assume $conn is the MySQL connection object and $query is the SQL query
$result = mysqli_query($conn, $query);
if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
// Output each row data here
echo $row['column_name'] . "<br>";
}
} else {
echo "No results found.";
}