title: Break UL tag after 'n' times in while-loop
body: <p>I'm currently in developing module shop for the company I work for and there is a little problem. While extracting records from the table, I want for every third data record to close HTML "UL" tag.  </p>
  
  <p>This is what I currently have:</p>
  
  <pre><code>&lt;?php
    $selektKat = "SELECT * FROM `proizvodi` WHERE `kategorija` = '$kat'"; //don't worry about SQLi; I will fix it
    $result = mysqli_query($con, $selektKat) or die(mysqli_error());
  
  // Line where the loop starts
  &lt;?php
  while ($row = mysqli_fetch_array($result)) { ?&gt;
  
    &lt;ul class="products-grid clearfix" style="margin-right: 5px; margin-left: 20px;"&gt;
    &lt;li class="item" style="min-height: 339px"&gt;
      &lt;a id="product-image-42321" href="proizvod.php" title="naziv" class="product-image"&gt;
        &lt;img src="http://static.511tactical.com/mag/media/catalog/product/cache/1/small_image/220x/9df78eab33525d08d6e5fb8d27136e95/5/3/53212_716_Alternate1.jpg" width="220" alt="&lt;?php echo $row['naziv'] ?&gt;" /&gt;
      &lt;/a&gt;
        &lt;ul class="swatches clearfix"&gt;
        &lt;li id="swatch-228" class="swatch product-42321"&gt;
          &lt;a href="proizvod.php" title="&lt;?php echo $row['naziv']; ?&gt;"&gt;
          &lt;img src="&lt;?php echo __DIR__ . '/images/' . $row['slika'] . '.jpg'; ?&gt;" /&gt;
          &lt;/a&gt;
        &lt;/li&gt;
        &lt;/ul&gt;
  
        &lt;div class="price-box"&gt;
          &lt;span class="label" id="configurable-price-from-42321"&gt;
            &lt;span class="configurable-price-from-label"&gt;
            &lt;/span&gt;
          &lt;/span&gt;
  
  
        &lt;div class="product-name"&gt;&lt;a id="product-name-140981" href="proizvod.php"&gt;&lt;?php echo $row['naziv']; ?&gt;&lt;/a&gt;&lt;/div&gt;
  
        &lt;span class="regular-price" id="product-price-42321"&gt;
          &lt;span class="price"&gt;&lt;?php echo $row['cijena']; ?&gt;&lt;sup&gt;KM&lt;/sup&gt;
          &lt;/span&gt;
        &lt;/span&gt;
        &lt;/div&gt;
  
        &lt;div class="actions"&gt;
        &lt;/div&gt;
  
    &lt;/li&gt;
  
  &lt;?php
  }
  ?&gt;
  &lt;/ul&gt; // This has to be closed in loop after every 3 records
  &lt;/div&gt;
  </code></pre>
  
  <p>Picture:
  <img src="https://i.stack.imgur.com/CMKtf.png" alt="enter image description here">  </p>
  
  <p>Cheers.</p>