What is the best way to implement automatic line breaks within a table when retrieving data from a database in PHP?
When retrieving data from a database in PHP and displaying it in a table, sometimes the content may be too long to fit within a table cell. To automatically add line breaks within the table cell to prevent the content from overflowing, you can use the `nl2br()` function in PHP. This function converts newlines in a string to HTML line breaks.
// Retrieve data from the database
$result = $mysqli->query("SELECT * FROM table");
// Display data in a table with automatic line breaks
echo "<table>";
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . nl2br($row['content']) . "</td>";
echo "</tr>";
}
echo "</table>";