What are some best practices for organizing and presenting MySQL query results in PHP?

When organizing and presenting MySQL query results in PHP, it is important to structure the data in a clear and user-friendly way. One best practice is to use HTML tables to display the results, with column headers for each field. Additionally, you can iterate through the query results using a loop to populate the table rows with data.

<?php
// Execute MySQL query and fetch results
$query = "SELECT * FROM table_name";
$result = mysqli_query($connection, $query);

// Display results in a HTML table
echo "<table>";
echo "<tr><th>ID</th><th>Name</th><th>Email</th></tr>";
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>";
?>