I have an application that contains a gallery page of user uploaded images. I am trying to show the images on a page using a foreach loop, but am having some problems with building the foreach loop.
This is the way the HTML is supposed to be formed
<div class="item">
<ul>
<li><a href="images/gallery/love1.jpg" rel="example1" ><img src="images/gallery/thumb_love1.jpg" alt="#" /></a></li>
<li><a href="images/gallery/love2.jpg" rel="example1" ><img src="images/gallery/thumb_love2.jpg" alt="#" /></a></li>
<li><a href="images/gallery/love3.jpg" rel="example1" ><img src="images/gallery/thumb_love3.jpg" alt="#" /></a></li>
<li><a href="images/gallery/love4.jpg" rel="example1"><img src="images/gallery/thumb_love4.jpg" alt="#" /></a></li>
<li><a href="images/gallery/love5.jpg" rel="example1" ><img src="images/gallery/thumb_love5.jpg" alt="#" /></a></li>
<li><a href="images/gallery/love6.jpg" rel="example1"><img src="images/gallery/thumb_love6.jpg" alt="#" /></a></li>
<li><a href="images/gallery/life1.jpg" rel="example1" ><img src="images/gallery/thumb_life1.jpg" alt="#" /></a></li>
<li><a href="images/gallery/life2.jpg" rel="example1"><img src="images/gallery/thumb_life2.jpg" alt="#" /></a></li>
<li><a href="images/gallery/life3.jpg" rel="example1"><img src="images/gallery/thumb_life3.jpg" alt="#" /></a></li>
</ul>
</div><!-- end item -->
So basically when the LI hits 9 items, break and start a new DIV of class="item"
Here is the PHP code I have been trying to work with
<?php
$x = range(1,100);
$counter = 1;
foreach($x as $item):
if($item == 9) {
?>
<div class="item">
<ul>
<?php foreach($pictures->result() as $p): ?>
<li><a href="images/gallery/<?=$p->category;?>/<?=$p->photo_name;?>" rel="example1" ><img src="images/gallery/<?=$p->category;?>/thumb_<?=$p->photo_name;?>" alt="#" /></a></li>
<?php endforeach; ?>
</ul>
</div><!-- end item -->
<?php $counter = 1;
} else {
$counter++;
} ?>
<?php endforeach; ?>
I have tried everything, but can't figure out how to make this work. Thanks in advance for any and all help!