Jump to content


Photo

Photo Gallery Help


  • Please log in to reply
1 reply to this topic

#1 dooper3

dooper3
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts
  • LocationLondon, UK

Posted 15 May 2006 - 12:14 PM

Hi!

I have made myself a photo gallery which is controlled by a MySQL database with a list of different gallery folders. The file gallery.php gets info from the MySQL table and shows a thumbnail and description for each gallery. When you click the thumbnail, it uses a GET clause to tell the PHP file browsegallery.php which gallery you've selected to browse. This file then counts the number of files in the directory of the chosen gallery, and shows them all in a table. My problem is that I want the browsegallery.php file to be able to stop showing images which aren't there and end the table when the number of photos present have all been displayed.

Below is my code so far...

<?
include("top.html");
echo("SULSC - Photo Gallery");
include("top2.html");
echo("<table align=\"center\">");
include("db_connect.php");
$sql = mysql_query("SELECT * FROM galleries WHERE id='$_GET[galleryid]'")
    or die (mysql_error());
$result = mysql_fetch_array($sql);
extract($result);
$i=0;
if ($handle = opendir($galleryfolder)) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != ".." && $file != "Thumbs.db") {
           $fName = $file;
           $file = $path.'/'.$file;
           if(is_file($file)) $numfile++;
            $photos[$i++]=$fName;
       }
   }
   closedir($handle);
}
mysql_close();
$n=0;
while($n<=$rowmax) {
    for ($rows=1;$rows<=4;$rows++) {
        for ($cols=1;$cols<=6;$cols++) {
            echo("<td><a href=\"$galleryfolder/$photos[$n]\" title=\"click for full sized image\"><img src=\"$galleryfolder/$photos[$n]\" border=\"0\" width=\"120\"></a></td>");
            $n++;
        }
        echo("</tr><tr>");
    }
}
echo("</tr></table>");
include("end.html");
?>

Thanks everyone!
Personal: charliehawker.com
Educational: fantasticode.com

#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 15 May 2006 - 02:32 PM

I've combined your two loops into one, and removed some variables you declare but never use. See if that helps.

<? include("top.html");
echo("SULSC - Photo Gallery");
include("top2.html");
echo("<table align=\"center\">");
include("db_connect.php");
$sql = mysql_query("SELECT * FROM galleries WHERE id='$_GET[galleryid]'")
    or die (mysql_error());
$result = mysql_fetch_array($sql);
extract($result);
$i=22;
if ($handle = opendir($galleryfolder)) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != ".." && $file != "Thumbs.db") {
            if($i>6) { echo "<tr>"; $i=0; }
            echo "<td><a href=\"$galleryfolder/$file\" title=\"click for full sized image\"><img src=\"$galleryfolder/$photos[$n]\" border=\"0\" width=\"120\"></a></td>";
       }
   }
   closedir($handle);
}
echo "</table>";
mysql_close();
echo("</tr></table>");
include("end.html");
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users