html - PHP col row grid system ← (PHP, HTML)

Im trying to make a webshop, but i have a grid system problem with PHP.

how it looks right now

<section class="container" id="products">
        <div class="row">
          <?php while($row = $result->fetch()):?>
            <div class="col">
              <?php include 'WebShop/kategorien/card.php'?>
            </div>
          <?php endwhile;?>
        </div>
</section>

It would be great, if the row could have only max 4 elements and then start a new line

Answer



Solution:

How's this:

<section class="container" id="products">
    <div class="row">
    <?php
        $in_this_row = 0;
        while($row = $result->fetch()):
    ?>
        <div class="col">
            <?php include 'WebShop/kategorien/card.php'?>
        </div>
    <?php
        $in_this_row += 1;
        if ($in_this_row == 4)
        {
            $in_this_row = 0;
    ?>
    </div>
    <div class="row">
    <?php
        }

        endwhile;
    ?>
    </div>
</section>

Source