What are common formatting issues when displaying SQL query results in a PHP script?

One common formatting issue when displaying SQL query results in a PHP script is that the data may not be displayed in a visually appealing way, making it difficult to read and understand. To solve this, you can format the results into a table structure using HTML to make it more organized and easier to read.

// Assume $result is the result of your SQL query

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

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

echo "</table>";