dooper3 Posted May 15, 2006 Share Posted May 15, 2006 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! Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted May 15, 2006 Share Posted May 15, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.