title: PHP create a new <ul> after every fifth element in a while loop
body: <p>Hello I'm trying to output a MySQL query result as a list so that after every fifth line I would like to create a new list.
  I did it the same way it was suggested before to a similar question of mine and it separates the results after the fifth line but in every new list the first element is the same as the last in the previous list.</p>
  
  <p>I used this code:</p>
  
  <pre><code>/*there is a mysqli query before this*/
  $i = 0;
  $count = $res-&gt;num_rows;
  echo '&lt;ul&gt;';
  while($obj = $res-&gt;fetch_object()){
      $i++;
      $exturl = $obj-&gt;link;
      $extname = utf8_encode($obj-&gt;title);
      echo '&lt;li&gt;&lt;a class="URL" title="'.$extname.'" href="'.$exturl.'" target="_blank"&gt;'.$extname.'&lt;/a&gt;&lt;/li&gt;';
      if($i % 5 == 0 &amp;&amp; $i &lt; $count){
          echo '&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;&lt;a class="URL" title="'.$extname.'" href="'.$exturl.'" target="_blank"&gt;'.$extname.'&lt;/a&gt;&lt;/li&gt;';
      }
  }
  echo '&lt;/ul&gt;';
  </code></pre>
  
  <p>And the question is, how can I avoid the duplications?</p>