I'm setting up an advertising portfolio and have the data pulled and displayed so that every fourth loop, there is an alternate class and a clearing div…it works great, except that the very first result has a clear after it. I'm using modulus and I'm assuming it's something with the $i=0 (if I use $i=1, it works perfectly, but skips the first result).
Can anyone suggest how to get around this?
I'm a designer, not a coder, so please bare with my lack of php knowledge!
Here's what I've got now:
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$client=mysql_result($result,$i,"Client");
$type=mysql_result($result,$i,"Type");
$image=mysql_result($result,$i,"Image");
$link=mysql_result($result,$i,"Link");
if($i % 4 == 0)
{
// This loop should have class="projectBoxlast"
$class = 'projectBoxlast';
}
else
{
// Others have projectBox
$class = 'projectBox';
}
if($i % 4 == 0 )
{
// This loop has a clear
$clear = '<div class="clear"></div>';
}
else
{
// Others have don't clear
$clear = '';
}
?>
<a href="<? echo "$link"; ?>">
<div class="<? echo "$class"; ?>">
<img class="thumbImage" src="http://www.cross-a.com/portfolio/thumbs/<? echo "$image"; ?>.jpg" />
<p class="thumbText"><strong><? echo "$client"; ?></strong><br />
<? echo "$type"; ?></p>
<div class="clear"></div>
</div> <!-- End of projectBox -->
</a>
<? echo "$clear"; ?>
<?
++$i;
}
?>