Jump to content

[SOLVED] Show last row - code to display an image


Bricktop

Recommended Posts

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;
    		}

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.

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!

Archived

This topic is now archived and is closed to further replies.

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