title: Divide data into three columns in while loop
body: <p>On my website I'm using a three column layout to display some cards - a bit like Google+. However, the cards I'm displaying are dynamic as in I don't know how many will be displayed. I don't know how I can divide these over the three columns evenly.</p>
  
  <p>This is a typical column:</p>
  
  <pre><code>&lt;div class="col-md-4 col-sm-6"&gt;
  
      &lt;div class="panel panel-default"&gt;
          &lt;div class="panel-heading"&gt;&lt;a href="#" class="pull-right"&gt;View all&lt;/a&gt; &lt;h4&gt;A Title here.&lt;/h4&gt;&lt;/div&gt;
          &lt;div class="panel-body"&gt;
              &lt;p&gt;&lt;img src="//placehold.it/150x150" class="img-circle pull-right"&gt; &lt;a href="#"&gt;A description here.&lt;/a&gt;&lt;/p&gt;
              &lt;div class="clearfix"&gt;&lt;/div&gt;
              &lt;hr&gt;
              Some text here.
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="panel panel-default"&gt;
          &lt;div class="panel-heading"&gt;&lt;a href="#" class="pull-right"&gt;View all&lt;/a&gt; &lt;h4&gt;A Title here.&lt;/h4&gt;&lt;/div&gt;
          &lt;div class="panel-body"&gt;
              &lt;p&gt;&lt;img src="//placehold.it/150x150" class="img-circle pull-right"&gt; &lt;a href="#"&gt;A Description here.&lt;/a&gt;&lt;/p&gt;
              &lt;div class="clearfix"&gt;&lt;/div&gt;
              &lt;hr&gt;
              Some text here.
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>This is the PHP loop I use - it's fairly standard: <code>while($row = mysql_fetch_assoc($result)) { }</code></p>
  
  <p>There are three of these and ideally I want the cards to be evenly distributed over the three columns.</p>