Unknown number of results into 3 columns creating 4 columns instead MySQL/PHP
<p>I have a query that fetches some data from a table and I would like to display the data evenly over 3 columns however if the num of returned results is not equally divisible by 3 the script creates a forth column. My script is:</p>

<pre><code>$columnCount = 0;
$howManyPerColumn = mysqli_num_rows($get_category_query) / 3;

&lt;div class="listingCategoryListWrapper"&gt;
  &lt;ul class="categoryList"&gt;
    &lt;?php
      while($get_category_result = mysqli_fetch_assoc($get_category_query)){
          $columnCount++;
          if($columnCount &lt;= $howManyPerColumn){
            echo('&lt;li&gt;&lt;input name="txtCategory[]" type="checkbox" /&gt;List item&lt;/li&gt;');
          }
          else
          {
            echo('&lt;/ul&gt;&lt;/div&gt;&lt;div class="listingCategoryListWrapper"&gt;&lt;ul class="categoryList"&gt;&lt;li&gt;&lt;input name="txtCategory[]" type="checkbox" /&gt;List item&lt;/li&gt;');
            $columnCount = 1;
          }
      }
    ?&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</code></pre>
