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.
I used this code:
/*there is a mysqli query before this*/
$i = 0;
$count = $res->num_rows;
echo '<ul>';
while($obj = $res->fetch_object()){
$i++;
$exturl = $obj->link;
$extname = utf8_encode($obj->title);
echo '<li><a class="URL" title="'.$extname.'" href="'.$exturl.'" target="_blank">'.$extname.'</a></li>';
if($i % 5 == 0 && $i < $count){
echo '</ul><ul><li><a class="URL" title="'.$extname.'" href="'.$exturl.'" target="_blank">'.$extname.'</a></li>';
}
}
echo '</ul>';
And the question is, how can I avoid the duplications?
Whats the point of appending the last li in the conditional?
Since you already echoed it out above the if $i % 5 statement.