kernelgpf Posted December 31, 2006 Share Posted December 31, 2006 The problem is I've deleted a couple of images from the gallery and will need to in the future, but when I do, if the random counter chooses the ID of the gallery image deleted, I get a read error. So I was TRYING to do a test like "if the image is there, show it, if not, keep trying until you do get a valid image".. but I tried several while, do while loops.. I'm not familiar with these, I do for loops, so if I could get some advice on the code below, I'd appreciate it.[code]print "<table align=left border=2>";$query=mysql_query("select COUNT(*) from gallery");$num=mysql_fetch_array($query);$arr = array();while ( count($arr) < 9 ) { $x = mt_rand(1,$num[0]); if ( !in_array($x,$arr) ) { $arr[] = $x; }}do{$query=mysql_query("select submittedby,filename,imagetitle,submissionID from gallery where submissionID='$arr[1]'");$row1=mysql_fetch_array($query);$image[1]="/gallery/$row1[filename]";} while(empty($row1[filename]));/*while(empty($row2[filename])){$query=mysql_query("select submittedby,filename,imagetitle,submissionID from gallery where submissionID='$arr[2]'");$row2=mysql_fetch_array($query);$image[2]="/gallery/$row2[filename]";}while(empty($row3[filename])){$query=mysql_query("select submittedby,filename,imagetitle,submissionID from gallery where submissionID='$arr[3]'");$row3=mysql_fetch_array($query);$image[3]="/gallery/$row3[filename]";}while(empty($row4[filename])){$query=mysql_query("select submittedby,filename,imagetitle,submissionID from gallery where submissionID='$arr[4]'");$row4=mysql_fetch_array($query);$image[4]="/gallery/$row4[filename]";}while(empty($row5[filename])){$query=mysql_query("select submittedby,filename,imagetitle,submissionID from gallery where submissionID='$arr[5]'");$row5=mysql_fetch_array($query);$image[5]="/gallery/$row5[filename]";}while(empty($row6[filename])){$query=mysql_query("select submittedby,filename,imagetitle,submissionID from gallery where submissionID='$arr[6]'");$row6=mysql_fetch_array($query);$image[6]="/gallery/$row6[filename]";}while(empty($row7[filename])){$query=mysql_query("select submittedby,filename,imagetitle,submissionID from gallery where submissionID='$arr[7]'");$row7=mysql_fetch_array($query);$image[7]="/gallery/$row7[filename]";}while(empty($row8[filename])){$query=mysql_query("select submittedby,filename,imagetitle,submissionID from gallery where submissionID='$arr[8]'");$row8=mysql_fetch_array($query);$image[8]="/gallery/$row8[filename]";}while(empty($row9[filename])){$query=mysql_query("select submittedby,filename,imagetitle,submissionID from gallery where submissionID='$arr[9]'");$row9=mysql_fetch_array($query);$image[9]="/gallery/$row9[filename]";}for($i=1;$i<10;$i++){print "$image[$i] - $arr[$i]<br>";}/*list($width,$height) = getimagesize("$v$image[1]");if($width+$height > 300){$width=$width/3;$height=$height/3;}print "<table align=center><tr><td><table align=left border=2><tr><td><a href='gallery.php?artID=$row1[submissionID]'><img src='$image[1]' width=$width height=$height border=0></a></td></tr>";exit;list($width,$height) = getimagesize("$v$image[2]");if($width+$height > 300){$width=$width/3;$height=$height/3;}print "<tr><td><a href='gallery.php?artID=$row2[submissionID]'><img src='$image[2]' width=$width height=$height border=0></a></td></tr>";list($width,$height) = getimagesize("$v$image[3]");if($width+$height > 300){$width=$width/3;$height=$height/3;}print "<tr><td><a href='gallery.php?artID=$row3[submissionID]'><img src='$image[3]' width=$width height=$height border=0></a></td></tr>";list($width,$height) = getimagesize("$v$image[4]");if($width+$height > 300){$width=$width/3;$height=$height/3;}print "<tr><td><a href='gallery.php?artID=$row4[submissionID]'><img src='$image[4]' width=$width height=$height border=0></a></td></tr></table></td> ";list($width,$height) = getimagesize("$v$image[5]");print "<td><table align=center border=2><tr><td><a href='gallery.php?artID=$row5[submissionID]'><img src='$image[5]' border=0></a></td></tr></table></td> ";list($width,$height) = getimagesize("$v$image[6]");if($width+$height > 300){$width=$width/3;$height=$height/3;}print "<td><table border=2 align=right><tr><td><a href='gallery.php?artID=$row6[submissionID]'><img src='$image[6]' width=$width height=$height border=0></a></td></tr>";list($width,$height) = getimagesize("$v$image[7]");if($width+$height > 300){$width=$width/3;$height=$height/3;}print "<tr><td><a href='gallery.php?artID=$row7[submissionID]'><img src='$image[7]' width=$width height=$height border=0></a></td></tr>";list($width,$height) = getimagesize("$v$image[8]");if($width+$height > 300){$width=$width/3;$height=$height/3;}print "<tr><td><a href='gallery.php?artID=$row8[submissionID]'><img src='$image[8]' width=$width height=$height border=0></a></td></tr>";list($width,$height) = getimagesize("$v$image[9]");if($width+$height > 300){$width=$width/3;$height=$height/3;}print "<tr><td><a href='gallery.php?artID=$row9[submissionID]'><img src='$image[9]' width=$width height=$height border=0></a></td></tr></table></td></tr></table>";[/code] Link to comment https://forums.phpfreaks.com/topic/32387-gallery-script-not-working/ Share on other sites More sharing options...
kernelgpf Posted December 31, 2006 Author Share Posted December 31, 2006 $v is my server's directory thing. It's set, don't worry. =) Link to comment https://forums.phpfreaks.com/topic/32387-gallery-script-not-working/#findComment-150402 Share on other sites More sharing options...
kernelgpf Posted January 1, 2007 Author Share Posted January 1, 2007 ..bump? Link to comment https://forums.phpfreaks.com/topic/32387-gallery-script-not-working/#findComment-150947 Share on other sites More sharing options...
corbin Posted January 1, 2007 Share Posted January 1, 2007 When ever it sets the filename such as $image[1]="/gallery/$row1[filename]"; you could do if(file_exists("/gallery/$row1['filename']"){$image[1]="/gallery/$row1[filename]";}Basically what I would do is something like[code=php:0]<?//pretend a mysql link is already established lol$q = mysql_query("select submittedby,filename,imagetitle,submissionID from gallery ORDER BY submissionID ASC")$i = 0;while($r = mysql_query($q)) {$fn = $r['filename'];if(file_exists("your/folder/with/pictures/{$fn}")) {$files[$i]['filename'] = $fn;$files[$i]['imagetitle'] = $r['imagetitle'];$files[$i]['submittedby'] = $r['submittedby'];$files[$i]['submissionID'] = $r['submissionID'];$size = getimagesize("your/folder/with/pictures/{$fn}");$files[$i]['width'] = $size[0];$files[$i]['height'] = $size[1];$i++;}}function output_pic($id, $file, $submitter, $title, $width, $height) {?><table align="center"><tr><td><table align="left" border="2"><tr><td><a href='gallery.php?artID=<?=$id;?>'><img src='your/folder/with/pictures/<?=$file;?>' width="<?=$width;?>" height="<?=$height;?>" border="0"></a></td></tr>";<?}foreach($files as $k => $v) {$id = $v['submissionID'];$file = $v['filename'];$submitter = $v['submittedby'];$title = $v['imagetitle'];$width = $v['width'];$height = $v['height'];//not really sure where your /3 came from, but here it goesif(($width + $height) > 300)) {$wid = $width/3;$hei = $height/3;} else {$wid = $width;$hei = $height;}output_pic($id, $file, $submitter, $title, $wid, $hei);}?>[/code] Link to comment https://forums.phpfreaks.com/topic/32387-gallery-script-not-working/#findComment-150956 Share on other sites More sharing options...
kernelgpf Posted January 2, 2007 Author Share Posted January 2, 2007 Wow, thanks so much Corbin, that helped a ton. ^^ Link to comment https://forums.phpfreaks.com/topic/32387-gallery-script-not-working/#findComment-151632 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.