Jump to content

Photo Gallery Help


dooper3

Recommended Posts

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...

[code]
<?
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");
?>
[/code]

Thanks everyone!
Link to comment
Share on other sites

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

[code]<? 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");
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.