Bricktop Posted August 28, 2008 Share Posted August 28, 2008 Hello all, I am using the below code to display a list of thumnail images, then I'm using some Javascript code to display the full-size image using an "onclick" event. All of this works tickety boo, but when the gallery page loads, because no one has yet clicked a thumbnail, the main image holder on the page just shows a blank box with an ugly image not found red cross. What I would like to do is somehow always show the first image in the set. Is there anyway I can achieve this do you know? I hope so but I'm a little concerned as to the fact that it's an onclick event I'm using. My code is below - I've added a firsrow=true/false line into the loop already - maybe we could work on that? Thanks $sql = mysql_query("SELECT * FROM gallery ORDER BY id"); $firstRow = true; while ($a = mysql_fetch_array($sql)) { $content .= '<li><a href="'.$a['path'].''.$a['filename'].'" onclick="showPicture(this); return false;" title="'.str_replace('"','"',$a[description]).'"><img src="'.$a['thumbnailpath'].''.$a['filename'].'" alt="'.str_replace('"','"',$a[description]).'" /></a></li>'; $firstRow = false; } Link to comment https://forums.phpfreaks.com/topic/121682-solved-show-last-row-code-to-display-an-image/ Share on other sites More sharing options...
swamp Posted August 28, 2008 Share Posted August 28, 2008 You could use something like this: <script> function fixBrokenImage(){ var imglst = document.images; for(var i = 0; i < imglst.length; i++){ imglst[i].onerror = function() { this.src = "myimage.gif"; } imglst[i].src = imglst[i].src; } } </script> then use <body onLoad="fixBrokenImage();"> Just change myimage to the image you want to use as default. Link to comment https://forums.phpfreaks.com/topic/121682-solved-show-last-row-code-to-display-an-image/#findComment-627709 Share on other sites More sharing options...
Bricktop Posted August 28, 2008 Author Share Posted August 28, 2008 Hi, thanks Swamp but I don't think it would be dynamic, I would like that image to change if the user uploads a new image. Essentially, the last image to be uploaded will always be theimage shown when the Gallery page loads. Link to comment https://forums.phpfreaks.com/topic/121682-solved-show-last-row-code-to-display-an-image/#findComment-627713 Share on other sites More sharing options...
swamp Posted August 28, 2008 Share Posted August 28, 2008 Oh sorry - only skimmed through your first post I thought you just wanted to fix it with the same image everytime.. I'll have a look into it for you Link to comment https://forums.phpfreaks.com/topic/121682-solved-show-last-row-code-to-display-an-image/#findComment-627716 Share on other sites More sharing options...
Bricktop Posted August 28, 2008 Author Share Posted August 28, 2008 Hi Swamp, Thanks but just cracked it - the HTML code to show dynamically show the image was: <img id="placeholder" src="" alt="Image Viewer" /> I assumed the "src=" had to be kept blank - I just tried inserting an image URL into that and the image still changes with the onlick event! Thanks for looking into it for me though matey! Link to comment https://forums.phpfreaks.com/topic/121682-solved-show-last-row-code-to-display-an-image/#findComment-627718 Share on other sites More sharing options...
swamp Posted August 28, 2008 Share Posted August 28, 2008 Cool Link to comment https://forums.phpfreaks.com/topic/121682-solved-show-last-row-code-to-display-an-image/#findComment-627719 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.