title: Dynamically load a <ul> and sort into columns of 5 rows
body: <p>Ok so I thought i would put this one out there. I have a list of 25 entries in my db which I would like to display on my page, in list form, in 5 columns with 5 rows. </p>
  
  <p>I prepared a solution, albeit not such an elegant one.</p>
  
  <pre><code>&lt;?php
  
                              $query = "SELECT * FROM city ORDER BY name ASC";
                              $result = mysql_query($query, $connection);
                              confirm_query($result);
  
                              echo "&lt;ul class=\"floatleft\"&gt;";
  
                              $counter = 1;
                              while ($row = mysql_fetch_array($result)) {
  
                              if ($counter &lt;= 5) {
  
                                      echo "&lt;li&gt;{$row["name"]}&lt;/li&gt;";
                                      $counter = $counter + 1;
  
                                          if ($counter == 6) {
                                              echo "&lt;/ul&gt;";
                                          }
  
                                  } elseif($counter &gt; 5 &amp;&amp; $counter &lt;= 10) {
  
                                          if ($counter == 6){
                                              echo "&lt;ul class=\"floatleft\"&gt;";
                                          }
                                      echo "&lt;li&gt;{$row["name"]}&lt;/li&gt;";
  
                                      $counter += 1;
  
                                          if ($counter == 11) {
                                              echo "&lt;/ul&gt;";
                                          }
  
                                  } elseif($counter &gt; 10 &amp;&amp; $counter &lt;= 15) {
  
                                          if ($counter == 11){
                                              echo "&lt;ul class=\"floatleft\"&gt;";
                                          }
  
                                      echo "&lt;li&gt;{$row["name"]}&lt;/li&gt;";
  
                                      $counter += 1;
  
                                          if ($counter == 16) {
                                              echo "&lt;/ul&gt;";
                                          }
                                  } elseif($counter &gt; 15 &amp;&amp; $counter &lt;= 20) {
  
                                          if($counter == 16){
                                              echo "&lt;ul class=\"floatleft\"&gt;";
                                          }
  
                                      echo "&lt;li&gt;{$row["name"]}&lt;/li&gt;";
  
                                      $counter += 1;
  
                                          if ($counter == 21) {
                                              echo "&lt;/ul&gt;";
                                          }
  
                                  } elseif($counter &gt; 20 &amp;&amp; $counter &lt;= 25) {
  
                                      if($counter == 21){
                                          echo "&lt;ul class=\"floatleft\"&gt;";
                                      }
  
                                  echo "&lt;li&gt;{$row["name"]}&lt;/li&gt;";
  
                                      $counter += 1;
  
                                          if ($counter == 26) {
                                              echo "&lt;/ul&gt;";
                                          }
  
                                  }
  
                              }
  
                          ?&gt;
  </code></pre>
  
  <p>This will Output the following</p>
  
  <pre><code>&lt;ul class="floatleft"&gt;
  &lt;li&gt;Belfast&lt;/li&gt;
  &lt;li&gt;Birmingham&lt;/li&gt;
  &lt;li&gt;Brighton&lt;/li&gt;
  &lt;li&gt;Bristol&lt;/li&gt;
  &lt;li&gt;Cambridge&lt;/li&gt;
  &lt;/ul&gt;
  &lt;ul class="floatleft"&gt;
  &lt;li&gt;Cardiff&lt;/li&gt;
  &lt;li&gt;Carlisle&lt;/li&gt;
  &lt;li&gt;Edinburgh&lt;/li&gt;
  &lt;li&gt;Glasgow&lt;/li&gt;
  &lt;li&gt;Hull&lt;/li&gt;
  &lt;/ul&gt;
  &lt;ul class="floatleft"&gt;
  &lt;li&gt;Lancaster&lt;/li&gt;
  &lt;li&gt;Leeds&lt;/li&gt;
  &lt;li&gt;Leicester&lt;/li&gt;
  &lt;li&gt;Liverpool&lt;/li&gt;
  &lt;li&gt;London&lt;/li&gt;
  &lt;/ul&gt;
  &lt;ul class="floatleft"&gt;
  &lt;li&gt;Manchester&lt;/li&gt;
  &lt;li&gt;Newcastle&lt;/li&gt;
  &lt;li&gt;Norwich&lt;/li&gt;
  &lt;li&gt;Nottingham&lt;/li&gt;
  &lt;li&gt;Oxford&lt;/li&gt;
  &lt;/ul&gt;
  &lt;ul class="floatleft"&gt;
  &lt;li&gt;Plymouth&lt;/li&gt;
  &lt;li&gt;Portsmouth&lt;/li&gt;
  &lt;li&gt;Southampton&lt;/li&gt;
  &lt;li&gt;Swansea&lt;/li&gt;
  &lt;li&gt;York&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Does anybody know of a better way of doing this? I'm still new to php, and I kbnow there must be a better, neater way of doing this.</p>