ebolt007 Posted May 12, 2010 Share Posted May 12, 2010 So I'm working on an image gallery, pulling in from a database. How do I set this up so the image links aren't always on the page? Currently I always have the 10 squares with "no pic" in the squares missing the images that I haven't loaded. How do I set this code to only have the links if an image is actually in the datbase? $sql = "SELECT * FROM Events WHERE ID = '$event_id'"; $query_result = mysql_query($sql); $Content_row = mysql_fetch_assoc($query_result); $image01 = $Content_row['Image1FileName']; $image02 = $Content_row['Image2FileName']; $image03 = $Content_row['Image3FileName']; $image04 = $Content_row['Image4FileName']; $image05 = $Content_row['Image5FileName']; $image06 = $Content_row['Image6FileName']; $image07 = $Content_row['Image76FileName']; $image08 = $Content_row['Image8FileName']; $image09 = $Content_row['Image9FileName']; $image10 = $Content_row['Image10FileName']; echo "<div class=\"event_pic_main\"><img src=\"images/events/$image01\" id=\"im\" ALT=\"no pic\" width=\"500\"></div>"."\n"; echo '<div class="event_pic_small_holder"> '."\n"; echo " <div class=\"event_pic_small\"><a href=\"#\" onclick=\"document.getElementById('im').src='images/events/$image01';return false;\"><img src=\"images/events/$image01\" width=\"40\" height=\"40\" ALT=\"no pic \" ></a></div> "."\n"; echo " <div class=\"event_pic_small\"><a href=\"#\" onclick=\"document.getElementById('im').src='images/events/$image02';return false;\"><img src=\"images/events/$image02\" width=\"40\" height=\"40\" ALT=\"no pic \" ></a></div> "."\n"; echo " <div class=\"event_pic_small\"><a href=\"#\" onclick=\"document.getElementById('im').src='images/events/$image03';return false;\"><img src=\"images/events/$image03\" width=\"40\" height=\"40\" ALT=\"no pic \" ></a></div> "."\n"; echo " <div class=\"event_pic_small\"><a href=\"#\" onclick=\"document.getElementById('im').src='images/events/$image04';return false;\"><img src=\"images/events/$image04\" width=\"40\" height=\"40\" ALT=\"no pic \" ></a></div> "."\n"; echo " <div class=\"event_pic_small\"><a href=\"#\" onclick=\"document.getElementById('im').src='images/events/$image05';return false;\"><img src=\"images/events/$image05\" width=\"40\" height=\"40\" ALT=\"no pic \" ></a></div> "."\n"; echo " <div class=\"event_pic_small\"><a href=\"#\" onclick=\"document.getElementById('im').src='images/events/$image06';return false;\"><img src=\"images/events/$image06\" width=\"40\" height=\"40\" ALT=\" no pic\"></a></div> "."\n"; echo " <div class=\"event_pic_small\"><a href=\"#\" onclick=\"document.getElementById('im').src='images/events/$image07';return false;\"><img src=\"images/events/$image07\" width=\"40\" height=\"40\" ALT=\"no pic \"></a></div> "."\n"; echo " <div class=\"event_pic_small\"><a href=\"#\" onclick=\"document.getElementById('im').src='images/events/$image08';return false;\"><img src=\"images/events/$image08\" width=\"40\" height=\"40\" ALT=\"no pic \"></a></div> "."\n"; echo " <div class=\"event_pic_small\"><a href=\"#\" onclick=\"document.getElementById('im').src='images/events/$image09';return false;\"><img src=\"images/events/$image09\" width=\"40\" height=\"40\" ALT=\"no pic \"></a></div> "."\n"; echo " <div class=\"event_pic_small\"><a href=\"#\" onclick=\"document.getElementById('im').src='images/events/$image10';return false;\"><img src=\"images/events/$image10\" width=\"40\" height=\"40\" ALT=\" no pic\"></a></div> "."\n"; echo '</div> '."\n"; ?> Thanks Link to comment https://forums.phpfreaks.com/topic/201553-images-always-showing-up/ Share on other sites More sharing options...
mattal999 Posted May 12, 2010 Share Posted May 12, 2010 $sql = "SELECT * FROM Events WHERE ID = '$event_id'"; $query_result = mysql_query($sql); $Content_row = mysql_fetch_assoc($query_result); $image = array(); $image[] = $Content_row['Image1FileName']; $image[] = $Content_row['Image2FileName']; $image[] = $Content_row['Image3FileName']; $image[] = $Content_row['Image4FileName']; $image[] = $Content_row['Image5FileName']; $image[] = $Content_row['Image6FileName']; $image[] = $Content_row['Image76FileName']; $image[] = $Content_row['Image8FileName']; $image[] = $Content_row['Image9FileName']; $image[] = $Content_row['Image10FileName']; echo "<div class=\"event_pic_main\"><img src=\"images/events/".$image[0]."\" id=\"im\" ALT=\"no pic\" width=\"500\"></div>"."\n"; echo '<div class="event_pic_small_holder"> '."\n"; foreach($image as $tempimage) { if($tempimage != "") { echo "<div class=\"event_pic_small\"><a href=\"#\" onclick=\"document.getElementById('im').src='images/events/".$tempimage."';return false;\"><img src=\"images/events/".$tempimage."\" width=\"40\" height=\"40\" ALT=\"no pic\"></a></div> "."\n"; } else { echo "NO_IMAGE_THING"; } } echo '</div> '."\n"; Link to comment https://forums.phpfreaks.com/topic/201553-images-always-showing-up/#findComment-1057419 Share on other sites More sharing options...
ebolt007 Posted May 12, 2010 Author Share Posted May 12, 2010 That makes sence to put them in an array, but that didn't work, it made the page just white, and I suck with arrays, anyone have any idea why mattal999's post didn't work? Nevermind, I fixed it, just had something wrong with the querry_results area. Thanks! Link to comment https://forums.phpfreaks.com/topic/201553-images-always-showing-up/#findComment-1057442 Share on other sites More sharing options...
litebearer Posted May 12, 2010 Share Posted May 12, 2010 perhaps try ... if(trim($tempimage} !== "") Link to comment https://forums.phpfreaks.com/topic/201553-images-always-showing-up/#findComment-1057446 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.