I made a mysql table on my website with backend that allows me to upload images of affiliate companies i deal with. I used this script and it works. I now have need to add URL to these.

As you can see i select the directory the iamges are in as the can be different for each page loaded.

This works:

<script language="JavaScript">

	// configuration structure
	var A_TPL = {
		// randomize the array each time page loads
		'random' : false,
		// number of transparency changes during the transition
		//	increase for smoother transition, reduce for less CPU usage
		'steps' : 20,
		// transition duration in seconds
		'transtime': .5,
		// slide time in seconds
		'slidetime': 1,
		// width of the slide (optional)
		'width' : 400,
		// height of the slide (optional)
		'height': 300,
		// alt text for the image (optional)
		'alt' : 'Website name',
		// css class assigned to the slide <img> (optional)
		'css' : ''
	};

	// list of images to display
	var A_ITEMS = [<?php
	
         //EXTRACT MYSQL PATH DATA
	$extract = mysql_query("SELECT * FROM images");

	while ($row = mysql_fetch_assoc($extract))
	{
	$directory = $row['imagedir'];
	}	
		$s_path = ($directory);
		$a_types = array ('jpg', 'jpeg');
		$a_images = array ();
		$h_dir = opendir($s_path);
		while ($s_file = readdir($h_dir)) {
			$s_type = strtolower(substr(strrchr($s_file, '.'), 1));
			if (in_array($s_type, $a_types))
				array_push($a_images, "\n\t\t'$s_path$s_file'");
		}
		closedir($h_dir);
		sort($a_images);
		echo join(',', $a_images);
?>

	];
	// fader initialization	
	var mySlideShow = new tFader (A_ITEMS, A_TPL);

    </script>

as you can see the var A_ITEMS gets the image names from the directory it finds in mysql.

i now want to try get the image directory, image name and url from mysql, the table is set up but im new to javasrcipt and it gives me different errors no matter what i try and do.

Note the lines with //

<script type="text/javascript">

var mygallery=new fadeSlideShow({
	wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
	dimensions: [250, 100], //width/height of gallery in pixels. Should reflect dimensions of largest image
	imagearray: [
		
var A_ITEMS = [<?php
	
	//EXTRACT MYSQL DATA
	$extract = mysql_query("SELECT * FROM images");

	while ($row = mysql_fetch_assoc($extract))
	{
	$imagefolder = $row['imagedir'];
	$imagefilename = $row['imagefile'];
	$imageurl = $row['imageurl'];
	
	echo ('"['$imagefolder'/,'$imagefilename'", "'$imageurl'", "_new"]'
	
	//["directory/imagename.jpg", "http://www.website.com/", "_new"],
	
	//PLEASE NOTE: Do not add 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>

you wil note these rows:

echo ('"'

im tryong to make the echo give data like row below:

//["directory/imagename.jpg", "http://www.website.com/", "_new"],

//PLEASE NOTE: Do not add trailing comma after very last image element!

Thats where i get stuck ... ho can i use the values from MYSQL and the trailing comma ?

I know its something stupid im doing

Member Avatar for stbuchok

Line 6 has a starting bracket.
Line 8 has a starting bracket.
Line 29 has an ending bracket.
Where is the second ending bracket?

It also would be cleaner if you used a webservice to get the image urls.

<?php
    //replace line 19
    echo $comma."[\"$imagefolder/$imagefilename\", \"$imageurl\", \"_new\"]" ;

   //add new line 20
    $comma=", ";
?>

stbuchok - thanks for your advise.

urtrivedi Thank you, it works, after making some changes like the imagefolder must be url to image like suggested, weird al these / \ i need to find out what they meen and how to use them ...

Thanlks guys you have no idea how i was stressing up this side

\ this is used to escape a character.

if you want to substitute variable value in string then you must prepare string in double quotes as i did.

$name="mikcy";
$mymessage= "welcome $name";  //'welcome $name'  will not substitute name.
echo $mymessage;

//output is 
welcome micky

Now you want name to be printed in double quotes, then you can not directly use it in string. if you use directly then php will think its end of string, so we use escape character

$name="mikcy";
//$mymessage= "welcome "$name" ";  //this will not work
$mymessage= "welcome \"$name\" ";  //this will work
echo $mymessage;

//output is 
welcome "micky"

I hope its clear now, If yes then mark this thread solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.