What are common pitfalls when trying to display data in a table using PHP?

Common pitfalls when displaying data in a table using PHP include not properly escaping user input, not handling empty datasets, and not formatting data correctly for display. To avoid these issues, make sure to sanitize user input, check for empty datasets before attempting to display them, and format data appropriately using HTML tags.

<?php
// Example code snippet to display data in a table with proper sanitation and formatting

// Assume $data is an array of data to display in the table

echo "<table>";
echo "<tr><th>Column 1</th><th>Column 2</th></tr>";

foreach ($data as $row) {
    echo "<tr>";
    echo "<td>" . htmlspecialchars($row['column1']) . "</td>";
    echo "<td>" . htmlspecialchars($row['column2']) . "</td>";
    echo "</tr>";
}

echo "</table>";
?>