notonurnelly Posted February 28, 2008 Share Posted February 28, 2008 Hi All, I have a number of thumbnail images that are pulled from a database, these are currently displayed down the page. I have an image place holder named walk. I want to be able to click any of the thumbnails and the the image in place holder walk will change to the current image. Here is my full code for the function. function display_interest_image_details($image_array,$SummitNo) { if (!is_array($image_array)) { echo '<br/>No images listed in this category<br/>'; } else { ?> <div id="Layer2"><img src="images/basket.jpg" name="walk" width="201" height="110" id="walk" /></div> <?php echo '<table width = "100%" border = 0 cellspacing =5>'; foreach ($image_array as $Image_Row) { $SummitNo = $Image_Row['key_id']; $Comment = $Image_Row['comment']; $ImageNo = $Image_Row['id'].".jpg"; $ImagePath = "/wain/images/fells/uploads/Interest/"; echo '<tr><p></p></tr>'; echo '<tr>'; echo '<td width ="100%"><div align="center">'; echo '<img src="'.$ImagePath."th_".$ImageNo.'" border=3';?> onclick="MM_swapImage('walk','','<?php echo "'.$ImagePath."th_".$ImageNo.'" ?>',1)" <?php //echo '<img src="'.$ImagePath."th_".$ImageNo.'" border=3 >'; echo '</div></td></tr><tr>'; echo '<td width ="100%"><div align="center">'; echo '<b>'.$Comment.'</b>'; echo '</div></td></tr>'; } echo '</table>'; } echo '<hr/>'; } my problem is on the following line echo '<img src="'.$ImagePath."th_".$ImageNo.'" border=3';?> onclick="MM_swapImage('walk','','<?php echo "'.$ImagePath."th_".$ImageNo.'" ?>',1)" I cannnot seem to append the Javascript into my PHP The following php to display the thumbnails works fine echo '<img src="'.$ImagePath."th_".$ImageNo.'" border=3 >'; Can anyone please help me to get this line of code right. Here is my javascript routine also function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } Many Thanks Jamie Quote Link to comment Share on other sites More sharing options...
fnairb Posted February 28, 2008 Share Posted February 28, 2008 I may be miscounting your single quotes but aren't these extra? onclick="MM_swapImage('walk','','<?php echo "'.$ImagePath."th_".$ImageNo.'" ?>',1)" Quote Link to comment Share on other sites More sharing options...
notonurnelly Posted February 28, 2008 Author Share Posted February 28, 2008 Im not sure, I have taken them out. With or without those in my page did not display. It only seems to work when I complety delete out the following line echo '<img src="'.$ImagePath."th_".$ImageNo.'" border=3';?> onclick="MM_swapImage('walk','','<?php echo ".$ImagePath."th_".$ImageNo." ?>',1)" and change the image dislay code to just echo '<img src="'.$ImagePath."th_".$ImageNo.'" border=3 >'; Thanks for oyur help anyhow, but I think the whole line is causing an error, hence my page is not dispaying Quote Link to comment Share on other sites More sharing options...
premiso Posted February 28, 2008 Share Posted February 28, 2008 echo '<img src="'.$ImagePath."th_".$ImageNo.'" border=3';?> onclick="MM_swapImage('walk','','<?php echo ".$ImagePath."th_".$ImageNo." ?>',1)" > You forgot to add the end > in the above line. Quote Link to comment Share on other sites More sharing options...
notonurnelly Posted February 28, 2008 Author Share Posted February 28, 2008 Uhm, I have now added that. When this line of code is in place, the lines of code after do not colour properly (im in dreamweaver) ie on the line that is incorrect the echo statement is blue this is correct the echo statement on the next line is then not the correct colour. Which I assume is telling me that I am not closing my php off correctly. Can this sort of thing be done, I mean embedding java into php Thanks Quote Link to comment Share on other sites More sharing options...
premiso Posted February 28, 2008 Share Posted February 28, 2008 Dreamweaver isnt the best PHP software at all. But yes it can be done: echo '<img src="'.$ImagePath."th_".$ImageNo.'" border=3';?> onclick="MM_swapImage('walk','','<?php echo $ImagePath . "th_" . $ImageNo; ?>',1)" > You had some invalid stuff, the above should take care of it. Quote Link to comment Share on other sites More sharing options...
notonurnelly Posted February 28, 2008 Author Share Posted February 28, 2008 Great, many thanks for that Im a little further that has allowed my page to be displayed. My main image is not changing when I click the thumbnails http://www.runthelakes.co.uk/wain/show_fell.php?SummitNo=137 click images tab, then point of interest Any ideas. Many Thanks Jamie Quote Link to comment Share on other sites More sharing options...
notonurnelly Posted February 29, 2008 Author Share Posted February 29, 2008 Can anyone else help me with this, my page is displaying with the following code, but my onClick actions are not working for each of the thumbnails http://www.runthelakes.co.uk/wain/show_fell.php?SummitNo=137 function display_interest_image_details($image_array,$SummitNo) { if (!is_array($image_array)) { echo '<br/>No images listed in this category<br/>'; } else { ?> <div id="Layer2"><img src="images/basket.jpg" name="walk" width="201" height="110" id="walk" /></div> <?php echo '<table width = "100%" border = 0 cellspacing =5>'; foreach ($image_array as $Image_Row) { $SummitNo = $Image_Row['key_id']; $Comment = $Image_Row['comment']; $ImageNo = $Image_Row['id'].".jpg"; $ImagePath = "/wain/images/fells/uploads/Interest/"; echo '<tr><p></p></tr>'; echo '<tr>'; echo '<td width ="100%"><div align="center">'; echo '<img src="'.$ImagePath."th_".$ImageNo.'" border=3';?> onclick="MM_swapImage('walk','','<?php echo $ImagePath . "th_" . $ImageNo; ?>',1)" > <?php //echo '<img src="'.$ImagePath."th_".$ImageNo.'" border=3 >'; echo '</div></td></tr><tr>'; echo '<td width ="100%"><div align="center">'; echo '<b>'.$Comment.'</b>'; echo '</div></td></tr>'; } echo '</table>'; } echo '<hr/>'; } I have a feeling the problem could still be in my javascript. Although the function below works on a static page function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } Many Thanks Jamie Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.