Hi,

I am javascript newbie.
I have a slideshow on my site and it works fine if I type in the images for it to display, however I want to get the image files path from my database, so it shows all the photos.

Here is the code I am working with.
I want to make all the image paths "images/photos/2.jpg" come from my database.
I have tried adding php into it but it doesn't work.

Any idea on how I can make this work??

<script type="text/javascript">

var mygallery=new fadeSlideShow({
	wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
	dimensions: [260, 210], //width/height of gallery in pixels. Should reflect dimensions of largest image
	imagearray: [
		["images/photos/2.jpg", "photos.php", "_new", "Some day I'd like to explore these caves!"],
		["images/photos/3.jpg"],
		["images/photos/4.jpg", "photos.php", "", "What a beautiful scene with everything changing colors."] //<--no trailing comma after very last image element!
	],
	displaymode: {type:'auto', pause:2500, cycles:0, wraparound:false},
	persist: false, //remember last viewed slide and recall within same session?
	fadeduration: 500, //transition duration (milliseconds)
	descreveal: "ondemand",
	togglerid: ""
})



</script>

Thanks for your help.

Cheers,

QWaz

I think its not possible to pass the value of php to your javascript.

You can use PHP for this. What was the PHP code you used to fetch the images from your database? You need to write a PHP variable then use an echo statement...

<script>
 document.write("<?php echo 'hello!'; ?>");
</script>

Otherwise you could use a different slideshow which takes images from within the page body (outside the JavaScript). e.g. http://www.magictoolbox.com/magicslideshow/

Hey QWaz,

Oh! great, we can pass the php value to javascript by the following method, I will give you a sample to pass a single variable

//PHP declaration
<?php $name='raja'?>
//Javascript
	<script type = 'text/javascript'>
		var hp="<?php echo $name; ?>";
		alert (hp);
	</script>

Hope this helps you to share your database value pass to javascript

Member Avatar

diafol

Should be straightforward:

["images/photos/2.jpg", "photos.php", "_new", "Some day I'd like to explore these caves!"],
		["images/photos/3.jpg"],
		["images/photos/4.jpg", "photos.php", "", "What a beautiful scene with everything changing colors."]

Build this with php variables and characters.

The gallery could be Ajaxified even. So that you don't need a page refresh to change the gallery pics.

Should be straightforward:

["images/photos/2.jpg", "photos.php", "_new", "Some day I'd like to explore these caves!"],
		["images/photos/3.jpg"],
		["images/photos/4.jpg", "photos.php", "", "What a beautiful scene with everything changing colors."]

Build this with php variables and characters.

The gallery could be Ajaxified even. So that you don't need a page refresh to change the gallery pics.

OP,

You are missing the closing ) in your function.