What is the best way to display the results of a DB query in an HTML table using PHP?
When displaying the results of a database query in an HTML table using PHP, you can use a combination of PHP and HTML to iterate over the query results and generate the table dynamically. You can fetch the results from the database, loop through each row, and output the data within HTML table tags. This approach allows for flexibility in styling and formatting the table as needed.
<?php
// Assuming $results is the variable containing the results of your database query
echo "<table>";
echo "<tr><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr>";
foreach ($results as $row) {
echo "<tr>";
echo "<td>" . $row['column1'] . "</td>";
echo "<td>" . $row['column2'] . "</td>";
echo "<td>" . $row['column3'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>