What are some best practices for displaying MySQL query results in PHP?

When displaying MySQL query results in PHP, it is important to properly format and present the data to the user. One best practice is to use HTML tables to organize the results in a clear and structured manner. Additionally, consider using CSS for styling and formatting the table to enhance the visual presentation of the data.

<?php
// Assuming $result is the variable containing the MySQL query result

echo "<table>";
echo "<tr><th>ID</th><th>Name</th><th>Email</th></tr>";

while($row = mysqli_fetch_assoc($result)) {
    echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['name'] . "</td>";
    echo "<td>" . $row['email'] . "</td>";
    echo "</tr>";
}

echo "</table>";
?>