timlondon Posted May 11, 2007 Share Posted May 11, 2007 Guys, I'm creating a javascript slideshow which works perfectly if the jpgs are prescribed as below. <script type="text/javascript"> <!-- var image1=new Image() image1.src="florida1.jpg" var image2=new Image() image2.src="florida2.jpg" var image3=new Image() image3.src="florida3.jpg" //--> </script> but instead of using the 3 prescribed florida jpgs I wanted to echo the jpg name as php variables what's the syntax?? My coding is currently: $xx=0; $xxx=1; while($xx < $totalslide) { $preload = $preload."var image".$xxx."=new Image()"; $preload = $preload." image".$xxx.".src=".$slideimage[$xx]." "; $xxx++; $xx++; } When echoed, $preload produces: var image1=new Image() image1.src=members/a/alpha01/Animpub/pubanalpha0118117.jpg var image2=new Image() image2.src=members/a/alpha01/Animpub/pubanalpha0118128.jpg var image3=new Image() image3.src=members/a/alpha01/Animpub/pubanalpha0118151.jpg This doesn't work with the remainder of the slideshow script presumably because the jpg path isn't wrapped in double quotes. So how can I get the double quotes into the script??????? Quote Link to comment https://forums.phpfreaks.com/topic/50917-phpjava/ Share on other sites More sharing options...
ToonMariner Posted May 11, 2007 Share Posted May 11, 2007 try this.... $xx=0; $xxx=1; $preload = NULL; while($xx < $totalslide) { $preload .= 'var image'.$xxx.'=new Image()'. "\r\n"; $preload .= 'image'.$xxx.'.src='".$slideimage[$xx].'";' . "\r\n"; $xxx++; $xx++; } echo $preload; Quote Link to comment https://forums.phpfreaks.com/topic/50917-phpjava/#findComment-250429 Share on other sites More sharing options...
timlondon Posted May 11, 2007 Author Share Posted May 11, 2007 Thanks Toon but it didn't work. For some reason the line $preload .= 'image'.$xxx.'.src='".$slideimage[$xx].'";' . "\r\n"; is left open (ie everything below it turns red). Quote Link to comment https://forums.phpfreaks.com/topic/50917-phpjava/#findComment-250438 Share on other sites More sharing options...
kenrbnsn Posted May 11, 2007 Share Posted May 11, 2007 You can reduce the code in the loop a little by doing: <?php $preload = array(); for($xx = 0;$xx < $totalslide; $xx++) { $xxx = $xx +1; $preload[] = 'var image'.$xxx.'=new Image()'; $preload[] = 'image' . $xxx . '.src="' . $slideimage[$xx] . '";'; } echo implode("\r\n",$preload)."\r\n"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/50917-phpjava/#findComment-250440 Share on other sites More sharing options...
timlondon Posted May 11, 2007 Author Share Posted May 11, 2007 Thanks guys it works!!!!! You gave me enough clues to work it out. Quote Link to comment https://forums.phpfreaks.com/topic/50917-phpjava/#findComment-250444 Share on other sites More sharing options...
Daniel0 Posted May 11, 2007 Share Posted May 11, 2007 FYI, Java != Javascript Quote Link to comment https://forums.phpfreaks.com/topic/50917-phpjava/#findComment-250469 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.