What is the best way to display database query results in multiple columns in PHP?

When displaying database query results in multiple columns in PHP, one way to achieve this is by using a loop to iterate through the results and formatting them into columns. This can be done by setting a specific number of columns to display the results in and using HTML table tags to structure the output.

<?php
// Assuming $results is an array of database query results
$numColumns = 3; // Number of columns to display the results in

echo '<table>';
echo '<tr>';
$count = 0;
foreach ($results as $result) {
    if ($count % $numColumns == 0 && $count != 0) {
        echo '</tr><tr>';
    }
    echo '<td>' . $result['column_name'] . '</td>';
    $count++;
}
echo '</tr>';
echo '</table>';
?>