PDA

View Full Version : How dynamically generate image source for Ultimate Fade-in slideshow with PHP/MySQL



imimin
07-27-2009, 05:45 AM
1) Script Title: Ultimate Fade-in slideshow (v1.5)
2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex14/fadeinslideshow.htm

3) Describe problem:
I REALLY like this script!
I am trying to set up Ultimate Fade-in slideshow so I can dynamically generate the first section of the script:



var fadeimages=new Array()
//SET IMAGE PATHS. Extend or contract array as needed
fadeimages[0]=["photo1.jpg", "", ""] //plain image syntax
fadeimages[1]=["photo2.jpg", "http://www.cssdrive.com", ""] //image with link syntax
fadeimages[2]=["photo3.jpg", "http://www.javascriptkit.com", "_new"] //image with link and target syntax

using PHP/MySQL. What I have done is the following:


<script type="text/javascript">

/***********************************************
* Ultimate Fade-In Slideshow (v1.51): Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var fadeimages=new Array()
//SET IMAGE PATHS. Extend or contract array as needed
<?php

/*$cat = mysql_real_escape_string($_GET['cat']);*/
$cat='all';

$get_items = "SELECT * FROM poj_products WHERE cat='$cat'";
$get_items = mysql_query($get_items);
while($item_row = mysql_fetch_assoc($get_items));
{
extract($item_row);
echo 'fadeimages[0]=["http://www.patternsofjoy.com/images/thumbs/'.$item_row['img-no_path'].'", "", ""]';
}
?>

var fadebgcolor="white"

////NO need to edit beyond here/////////////
. . .


but it does not seem to be working? Thank you, I would appreciate any help I can get :-) !

imimin
07-27-2009, 03:20 PM
It works if I don't use the loop, such as:


<?php
/*$cat = mysql_real_escape_string($_GET['cat']);*/
$cat='all';
$get_items = "SELECT * FROM poj_products WHERE cat='$cat'";
$get_items = mysql_query($get_items);
$item_row = mysql_fetch_assoc($get_items);
extract($item_row);
echo 'fadeimages[0]=["http://www.patternsofjoy.com/images/thumbs/'.$item_row['img-no_path'].'", "", ""]';
?>

but it only show the first record in the DB in the 'cat' field (but it is not looping through the other items in the DB).

Does anybody know how to fix this or is there another method by which I should atte4mpt to do this?

imimin
07-27-2009, 07:11 PM
OK...got it!

If you change the code and do something like this, it works:



<script type="text/javascript">

/***********************************************
* Ultimate Fade-In Slideshow (v1.51): Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var fadeimages=new Array()
//SET IMAGE PATHS. Extend or contract array as needed
<?php
/*$cat = mysql_real_escape_string($_GET['cat']);*/
$cat='all';
$get_items = "SELECT * FROM poj_products WHERE cat='$cat'";
$get_items = mysql_query($get_items);
$i = 0;
while($item_row = mysql_fetch_assoc($get_items))
{
extract($item_row);
echo 'fadeimages['.$i.']=["http://www.patternsofjoy.com/images/thumbs/'.$item_row['img-no_path'].'", "", ""]' . "\n";
$i++;
}
?>


var fadebgcolor="white"

////NO need to edit beyond here/////////////
. . .