How can you optimize the PHP code snippet provided for displaying database query results in a table format?
The PHP code snippet provided lacks proper HTML structure and styling to display the database query results in a table format. To optimize it, we can modify the code to include HTML table tags and style the table using CSS to improve readability and presentation of the data.
<?php
// Assuming $results is an array of database 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>';
?>