Forum Moderators: coopster
<?php for ($i=1; $i <= 14; $i++) { $f = $i/4; if (($f == "1") or ($f == "2") or ($f == "3")){ print "<br>"; } else { print "<a href=cell_pics/$i.jpg><img src=cell_pics/th/$i.jpg border=0></a> "; } } ?> what I want to simplyfy is the first condition of the if statement. right now I only have few pictures, but I'll add about 50+ images, and I don't want to add the ($f == "4"), ($f == "5"), ($f == "6")... hope someone can help me, thanks:
bivium
If all you want to do is get every fourth one then do something like this...
<?php
for ($i=1; $i <= 14; $i++) {
if ($i%4 == 0){
print "<br>";
} else {
print "<a href=cell_pics/$i.jpg><img src=cell_pics/th/$i.jpg border=0></a> ";
}
}
?>
What I've done here is use the modulus operator [us4.php.net] which returns the remainder of $i divided by 4. When the remainder equals zero then you got it!
Tim