What are some common tools or methods to format and display MySQL query results in a table using PHP?
When querying data from MySQL using PHP, it is common to want to format and display the results in a table for better readability. One way to achieve this is by using HTML table tags combined with PHP loops to iterate over the query results and output them row by row in the table format.
<?php
// Assuming $result is the variable containing the MySQL query results
echo "<table>";
echo "<tr><th>ID</th><th>Name</th><th>Email</th></tr>"; // Table header row
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['email']."</td>";
echo "</tr>";
}
echo "</table>";
?>