How can one ensure that the HTML table displays all results from a column before moving to the next column?

To ensure that the HTML table displays all results from a column before moving to the next column, you need to make sure that the data is fetched and displayed row by row. This can be achieved by looping through the data and creating a new table row for each record before moving to the next column. By following this approach, you can ensure that all results from a column are displayed before moving on to the next one.

<?php
// Sample data array
$data = array(
    array("Name" => "John", "Age" => 25),
    array("Name" => "Jane", "Age" => 30),
    array("Name" => "Alice", "Age" => 28)
);

echo "<table border='1'>";
echo "<tr><th>Name</th><th>Age</th></tr>";

foreach ($data as $row) {
    echo "<tr>";
    echo "<td>" . $row['Name'] . "</td>";
    echo "<td>" . $row['Age'] . "</td>";
    echo "</tr>";
}

echo "</table>";
?>