I wrote an image gallery script.
<?php
function createGallery($gF, $tF, $tW, $tH, $nR, $c1, $c2)
{
// $gF is the path to the folder that contains the images
// example: "gallery/"
// $tF is the path to the folder that contains the thumbnails of the images
// example: "gallery/thumbs/"
// $tW is the desired width of the thumbnails
// example: 120
// $tH is the maximum desired height of the thumbnails
// example: 80
// $nR is the desired number of images in each row of the table
// example: 8
// $c1 is the desried HTML BG color for every other table cell
// example: #CCCCCC
// $c2 is the desried HTML BG color for every other table cell
// example: #FFFFFF
echo " <tr>\n";
buildThumbs($gF, $tF, $tW, $tH);
// call to another function to generate the thumbs
$open = opendir($tF);
// open the directory to the thumbs folder
$i = 0;
// we use $i to loop $i amount of times and increment
while(FALSE !== ($fileName = readdir($open)))
{
$i++;
// increment $i by 1
if($fileName != "." && $fileName != "..")
{
// this removes the first two "." and ".." that are actually links to go
// up to the upper directories and not files
if(is_int($i / 2))
{
// if $i is not divisible by 2...
echo " <td bgcolor=\"" . $c1 . "\"><a href=\"" . $gF . $fileName . "\" title=\"" . $fileName . "\"><img src=\"" . $tF . $fileName . "\" border=\"0\"></a></td>\n";
}
else
{
echo " <td bgcolor=\"" . $c2 . "\"><a href=\"" . $gF . $fileName . "\" title=\"" . $fileName . "\"><img src=\"" . $tF . $fileName . "\" border=\"0\"></a></td>\n";
}
if(is_int($i / $nR))
{
// if $i is divisible by the number of images per row...
echo " </tr>\n <tr>\n";
}
}
}
closedir($open);
// close the directory
echo " </tr>\n";
}
// script goes on here for buildThumbs() function...
?>
This is the result I get:
<html>
<head>
<title>My gallery!</title>
</head>
<body>
<h1>My gallery!</h1>
<table cellpadding="5" border="1" bordercolor="green">
<tr>
<td bgcolor="#FFFFFF"><a href="mygallery/Photo Negative (photo by brokenarts).jpg" title="Photo Negative (photo by brokenarts).jpg"><img src="mygallery/thumbs/Photo Negative (photo by brokenarts).jpg" border="0"></a></td>
<td bgcolor="#CCCCCC"><a href="mygallery/Parchment (photo by brokenarts).jpg" title="Parchment (photo by brokenarts).jpg"><img src="mygallery/thumbs/Parchment (photo by brokenarts).jpg" border="0"></a></td>
<td bgcolor="#FFFFFF"><a href="mygallery/Paper clipped (photo by brokenarts).jpg" title="Paper clipped (photo by brokenarts).jpg"><img src="mygallery/thumbs/Paper clipped (photo by brokenarts).jpg" border="0"></a></td>
<td bgcolor="#CCCCCC"><a href="mygallery/Hands (photo by datarec).jpg" title="Hands (photo by datarec).jpg"><img src="mygallery/thumbs/Hands (photo by datarec).jpg" border="0"></a></td>
<td bgcolor="#FFFFFF"><a href="mygallery/Lime Light (photo by matchstick).jpg" title="Lime Light (photo by matchstick).jpg"><img src="mygallery/thumbs/Lime Light (photo by matchstick).jpg" border="0"></a></td>
<td bgcolor="#CCCCCC"><a href="mygallery/Handshake (photo by mikecco).jpg" title="Handshake (photo by mikecco).jpg"><img src="mygallery/thumbs/Handshake (photo by mikecco).jpg" border="0"></a></td>
<td bgcolor="#FFFFFF"><a href="mygallery/Butterflies (photo by lusi).jpg" title="Butterflies (photo by lusi).jpg"><img src="mygallery/thumbs/Butterflies (photo by lusi).jpg" border="0"></a></td>
<td bgcolor="#CCCCCC"><a href="mygallery/Future (photo by clix).jpg" title="Future (photo by clix).jpg"><img src="mygallery/thumbs/Future (photo by clix).jpg" border="0"></a></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><a href="mygallery/Hands holding a poster (photo by brokenarts).jpg" title="Hands holding a poster (photo by brokenarts).jpg"><img src="mygallery/thumbs/Hands holding a poster (photo by brokenarts).jpg" border="0"></a></td>
<td bgcolor="#CCCCCC"><a href="mygallery/Missing (photo by wilhei66).jpg" title="Missing (photo by wilhei66).jpg"><img src="mygallery/thumbs/Missing (photo by wilhei66).jpg" border="0"></a></td>
<td bgcolor="#FFFFFF"><a href="mygallery/Globalvillage (photo by davdibiase).jpg" title="Globalvillage (photo by davdibiase).jpg"><img src="mygallery/thumbs/Globalvillage (photo by davdibiase).jpg" border="0"></a></td>
<td bgcolor="#CCCCCC"><a href="mygallery/World Map (photo by spekulator).jpg" title="World Map (photo by spekulator).jpg"><img src="mygallery/thumbs/World Map (photo by spekulator).jpg" border="0"></a></td>
<td bgcolor="#FFFFFF"><a href="mygallery/Sales figures (photo by wag66).jpg" title="Sales figures (photo by wag66).jpg"><img src="mygallery/thumbs/Sales figures (photo by wag66).jpg" border="0"></a></td>
<td bgcolor="#CCCCCC"><a href="mygallery/Old sheet of paper (photo by brokenarts).jpg" title="Old sheet of paper (photo by brokenarts).jpg"><img src="mygallery/thumbs/Old sheet of paper (photo by brokenarts).jpg" border="0"></a></td>
<td bgcolor="#CCCCCC"><a href="mygallery/Business man modified (photo by Henkster).jpg" title="Business man modified (photo by Henkster).jpg"><img src="mygallery/thumbs/Business man modified (photo by Henkster).jpg" border="0"></a></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"><a href="mygallery/E-Sign (photo by erkinsahin).jpg" title="E-Sign (photo by erkinsahin).jpg"><img src="mygallery/thumbs/E-Sign (photo by erkinsahin).jpg" border="0"></a></td>
<td bgcolor="#FFFFFF"><a href="mygallery/Sun Burst (photo by thesaint).jpg" title="Sun Burst (photo by thesaint).jpg"><img src="mygallery/thumbs/Sun Burst (photo by thesaint).jpg" border="0"></a></td>
<td bgcolor="#CCCCCC"><a href="mygallery/Lens (photo by brokenarts).jpg" title="Lens (photo by brokenarts).jpg"><img src="mygallery/thumbs/Lens (photo by brokenarts).jpg" border="0"></a></td>
<td bgcolor="#FFFFFF"><a href="mygallery/Fingerprint (photo by brokenarts).jpg" title="Fingerprint (photo by brokenarts).jpg"><img src="mygallery/thumbs/Fingerprint (photo by brokenarts).jpg" border="0"></a></td>
<td bgcolor="#CCCCCC"><a href="mygallery/_Notes.jpg" title="_Notes.jpg"><img src="mygallery/thumbs/_Notes.jpg" border="0"></a></td>
<td bgcolor="#FFFFFF"><a href="mygallery/Polaroid Film (photo by hugoslv).jpg" title="Polaroid Film (photo by hugoslv).jpg"><img src="mygallery/thumbs/Polaroid Film (photo by hugoslv).jpg" border="0"></a></td>
</tr>
</table>
</body>
</html>
As you can see, one less table cell is in each row. Also, one time the #CCCCCC background color appears THREE TIMES in a row. Why is this? Shouldn't [font="Courier New"]is_int($var % $var2)[/font] do this fine? I don't understand.
Thanks in advance for your help!
~lupus6x9