How to make more columns in a while

I have this code

while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) {
            
            echo "
            <div><h4><a href=\"page.php?id={$row['subcategory_id']}\">{$row['subcategory']}</a></h4>
            </div>\n";
            
        }

With this while I put on a page a vertical line with subcategories. For ex:
foo
foo
foo
foo
foo
foo
foo

I want to limit those subcategories to 10 and after each 10 to start from the top again, like this:

foo foo foo
foo foo foo
foo foo foo
foo foo foo
foo foo foo
foo foo foo
foo foo foo

Can someone tell how to do that?

At least an idea, or a different way to do this?

Play around with this script:

$iCol = 0;
for($i2=0; $i2<42; $i2++) {

  if( $iCol++ % 3 === 0) {
    echo '<br />';
  }
  echo $i2, ', &nbsp;&nbsp;';

}

Output:

I was intrigued as to how to display vertically so…

  $cols = [];
  for($i2=0; $i2< 42; $i2++) {
    $cols[] = $i2;
  }

  $iMax = 10;
    for( $i2 = 0; $i2 < $iMax; $i2++){
      echo $cols[$i2+00] .', &nbsp; ';
      echo $cols[$i2+10] .', &nbsp; ';
      echo $cols[$i2+20] .', &nbsp; ';
      echo $cols[$i2+30] .', &nbsp; ';
      echo '<br />';
    }

Output:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.