problem displaying images

Please help. We are trying to create a page where thumbnails show on one part of the page where an onclick will produce a larger image on the same page. This code was created by Paul Whitrow from Gr0w. When we try to preview the code, no images show. The images come from an images folder in the site. Obviously we are missing something. Any help or direction would be greatly appreciated. The code is as follows:


<?php $imagesArray=array(); $imagesArray["src"][0]="images/carli-46-3-picts.jpg"; $imagesArray["alt"][0]="carli"; $imagesArray["src"][1]="images/cicadas.jpg"; $imagesArray["alt"][1]="cicadas"; $imagesArray["src"][2]="images/kids-5x7.jpg"; $imagesArray["alt"][2]="kids"; $imagesArray["src"][3]="images/seasonsofpond.jpg"; $imagesArray["alt"][3]="pond"; print_r($imagesArray["alt"]); $useImage=0; if(isset($_REQUEST)){ while(list($key,$val)=each($_REQUEST)){ if(strstr($key,"_img_x")){ $useImage=str_replace("_img_x","",$key); break; } } } ?> " id="imageSwapperForm" onsubmit="return false"> <? for($i=0; $i < count($imagesArray["src"]); $i++){ echo ''; } ?>

" width="250" height="250" border="0" alt="<?=$imagesArray["alt"][$useImage]?>" />

[/php] :cry:

MOD EDIT: added php tags for readability

Could you show us the output (HTML) code? I have a hunch it has to do with this bit of code, to be precise the single quotes in the onclick attribute:

echo ‘<input type=“image” name="’.$i.’_img" value="’.$i.’_img" src="’.$imagesArray[“src”][$i].’"
alt="’.$imagesArray[“alt”][$i].’" onclick=“document.getElementById(‘img’).src=this.src; document.getElementById(‘img’).alt=this.alt” />’;

I am embarrassed with my ignorance. We assumed this was the complete code. Obviously we are missing the output (html). Is there a resource you can direct us to on how to connect this php to an output? We thought it had something to do with the header not reading images and that is what we were focused on.

Ok, from the last suggestion we change the single quote to double and now get the images to display. However the onclick does not work to change the main viewable image, is there a syntax error or am I missing something?. Also in my need to understand this can anyone explain why the single qoutes do not display the image and the double qoutes do? In my book they are saying there is no big difference between the two.

Thank you

This is the code used for where the image is supposed to change upon clicking on the thumbnails. what am i missing.

" width="250" height="250" border="0" alt="<?=$imagesArray["alt"][$useImage]?>" />

As you can see in the highlighted code, the text in the single-quotes in the onclick attribute is rendered as PHP code. This doesn’t work, and you would have been notified of that had you used error_reporting(E_ALL). See the debugging link in my signature.

It still doesn’t work when changing the singlequotes to doublequotes because now the quotes don’t interfere with the PHP code anymore, but prematurely abort the onclick attribute. When developing, you should use a HTML validator in order to make sure your HTML makes sense. This issue would have popped up in that case.

The trick is to escape the quotes as single-quotes, so they don’t interfere with the onclick attribute and other HTML parts, and PHP does not see them as the ending of the string it’s supposed to echo.

Zyppora–thanks for the info. the escape helped. I am using Dreamweaver CS3 on a Mac (don’t know if this makes a difference) but in trying to view my errors in the display all I get is a blank screen. Searched all over on how to get it show but with no luck. Typed this in: error_reporting(E_ALL);
ini_set(‘display_errors’,‘On’);ini_set(‘display_errors’,‘On’);–when I take the escapes out, all I get is a blank screen. Using MAMP v.1.7. Someday we will be out of this newbie state. Thanks for your help.

Is there someone in the Chicagoland area I can contact for help?

Sponsor our Newsletter | Privacy Policy | Terms of Service