What are some best practices for formatting database query outputs in PHP to enhance visual appeal?

When displaying database query outputs in PHP, it is important to format the data in a visually appealing way for better readability. One way to enhance the visual appeal is to use HTML tables to organize the data in rows and columns. This can make it easier for users to scan through the information and understand the relationships between different data points.

// Assuming $results is the array containing the database query results

echo "<table>";
echo "<tr>";
foreach ($results[0] as $key => $value) {
    echo "<th>$key</th>";
}
echo "</tr>";

foreach ($results as $row) {
    echo "<tr>";
    foreach ($row as $value) {
        echo "<td>$value</td>";
    }
    echo "</tr>";
}

echo "</table>";