my PHP gallery script not working

Experts,

I am attempting to create a thumnail gallery for one of my websites.  I need the script to show five images per row, however this is not working currently, please help;

<?
// Paths to images
$thumbs = "thumbs";
$images = '/PHPgallery/images/';

// Image sizes
$height = "70px";
$xsize = "55px";


// Count number of files in folder

$d = dir("thumbs");
$numoffiles=0;
while($entry=$d->read()) {
      if (($entry<>'.') and ($entry<>'..')) $numoffiles++;
       }

$d->close();
 
// Thumbnail generator
if($dir = opendir($thumbs)){
echo "<table border=\"1\" cellspacing=\"5\">\n";
echo "<tr>\n";
$n = 0;
      for($x = 0; $file = readdir($dir); $x++) {
    $shorten = strtolower(substr($file, -3));
          if($shorten == "jpg" || $shorten == "gif" || $shorten == "png") {                    
        $path = "$thumbs"."/"."$file";
        $files[$n] = $path;    
        echo "<td width=\"80\" height=\"65\"><img src=\"$files[$n]\" height=\"$height\" width=\"$xsize=\"></td>"."\n";
        $n++;
            if($n % 5 == 0) echo '</tr><tr>';
            }
            echo "</table>\n";
        }
 
if($x == 0) {
print "No images found";
}
else {
print "Unable to open directory";
}
}
?>
mhouldridgeAsked:
Who is Participating?
 
HackneyCabConnect With a Mentor Commented:
It looks like you're echoing "</table>" in your for loop. So check your HTML output to see if </table> appears several times inside your table code. If that's what's happening, then I doubt most browsers would render the table the way you want. Move the echo "</table>" line to outside the for loop.
0
 
TeRReFCommented:
What's not working exactly?
0
 
Stacy SpearPresident/Principal ConsultantCommented:
This:

          }
          echo "</table>\n";
       }

Should be:

           }
       }
       echo "</table>\n";
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
HackneyCabCommented:
I get the feeling this is going to be another thread left to the page editors to handle. (Been a week with no reply.)
0
 
Stacy SpearPresident/Principal ConsultantCommented:
Wow, I didn't even notice, was just strolling through unanswered questions!

People should close the loop after all.
0
 
TeRReFCommented:
@HackneyCab
I know, it's one of the most frustrating things of EE. You try to help people and some of them do not have the decency to reply on the comments...
Anyway, for any future clean up voluteer. I think HackneyCab should get the points since he/ she pointed out the '</table> inside the loop' problem...
0
 
HackneyCabCommented:
He, TeRReF, and thank you for your vote.

Now I guess it's just another case of wait twenty-odd days to see if the page editor gets here before the original poster.
0
All Courses

From novice to tech pro — start learning today.