How can data from an SQL query be displayed in separate columns in an HTML table using PHP?

To display data from an SQL query in separate columns in an HTML table using PHP, you can fetch the data from the query result and then loop through each row to display the data in separate table columns. You can use HTML table tags within your PHP code to structure the data in a tabular format.

<?php
// Perform SQL query to fetch data
$query = "SELECT column1, column2, column3 FROM your_table";
$result = mysqli_query($connection, $query);

// Display data in HTML table
echo "<table>";
while($row = mysqli_fetch_assoc($result)) {
    echo "<tr>";
    echo "<td>" . $row['column1'] . "</td>";
    echo "<td>" . $row['column2'] . "</td>";
    echo "<td>" . $row['column3'] . "</td>";
    echo "</tr>";
}
echo "</table>";

// Free result set
mysqli_free_result($result);
?>