Output columns in a loop

Hello, there is a websitethat is interested in displaying categories, that is, it displays categories in a column, as soon as there are about 15 categories, it creates a new column and starts to continue there, Help with building 🙂 preferably recursion


Answer 1, authority 100%

echo '<div width="820">'; //  
    for ($i=1; $i<=5; $i++){ //5-
        for ($k=1; $k<=15; $k++){
            echo '<div width="164">';//  
            while ($row = mysql_fetch_assoc($query)) {
                echo '<a href="'.$row["link"].'">'.$row["link_name"].'</a><br/>';
            }
            echo '</div>';//  
        }    
    }
echo '</div>'; //   

Answer 2, authority 100%

<?php
$maxRowCount = 15; //  
$rubrik      = array(); //  
//   
$maxColCount = ceil(count($rubrik) / $maxRowCount);
//  
echo '<table>';
for ($i = 0; $i < $maxRowCount; $i++) {
    echo '<tr>';
    for ($j = 0; $j < $maxColCount; $j++) {
        if (array_key_exists($i + $j * $maxRowCount, $rubrik)) {
            echo '<td>' . $rubrik[$i + $j * $maxRowCount] . '</td>';
        } else {
            echo '<td></td>';
        }
    }
    echo '</tr>';
}
echo '</table>';
?>