What are some best practices for displaying query results in a table format using PHP?

When displaying query results in a table format using PHP, it is important to properly format the data to make it easy to read and understand for the user. This can be achieved by using HTML table tags to structure the data in rows and columns. Additionally, it is recommended to use CSS to style the table for better visual presentation.

<?php
// Assuming $results is an array containing the query results

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

foreach ($results as $row) {
    echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['name'] . "</td>";
    echo "<td>" . $row['email'] . "</td>";
    echo "</tr>";
}

echo "</table>";
?>