Results 1 to 4 of 4

Thread: Ultimate Fade-in slideshow (v2.1) - How can we dynamically add items to slideshow

  1. #1
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Ultimate Fade-in slideshow (v2.1) - How can we dynamically add items to slideshow

    1) Script Title: Ultimate Fade-in slideshow

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...nslideshow.htm

    3) Describe problem: Based on the current design of putting the list of images to use as a slideshow in the <head> and not the <bodu>, I am finding it to be extremely difficult to use php to dynamically populate this list from a database. Is there a known way to populate this list dynamically from a db? I love the code, and would use it if I could fill it from my database on page load.

    Any suggestions would be appreciated.
    Thanks,
    Mitch

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    It shouldn't be too difficult actually. The key is just to output the portion in red below inside your configuration code dynamically:

    Code:
    <script type="text/javascript">
    
    var mygallery=new fadeSlideShow({
    wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
    dimensions: [250, 180], //width/height of gallery in pixels. Should reflect dimensions of largest image
    imagearray: [
    ["http://i26.tinypic.com/11l7ls0.jpg", "", "", "Nothing beats relaxing next to the pool when the weather is hot."],
    ["http://i29.tinypic.com/xp3hns.jpg", "http://en.wikipedia.org/wiki/Cave", "_new", "Some day I'd like to explore these caves!"],
    ["http://i30.tinypic.com/531q3n.jpg"],
    ["http://i31.tinypic.com/119w28m.jpg", "", "", "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>
    The rest can remain static as is. You might end up with something like:
    Code:
    <script type="text/javascript">
    
    var mygallery=new fadeSlideShow({
    wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow
    dimensions: [250, 180], //width/height of gallery in pixels. Should reflect dimensions of largest image
    <?
    echo "imagearray:[\";
    $query = "SELECT * FROM gallery";
    $result = mysql_query($query);
    while($r=mysql_fetch_array($result)){
    echo "[\"$r[imagepath]\", \"$r[link]\", \"\", \"$r[descp]\"],\n";
    echo "],";
    ?>
    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>
    Note that the pseudo code above does not remove the very last comma (",") that should not exist after the very last array element of the image. You'll need to do that.

    Basically the idea is just to output the aforementioned chunk of code inside the script dynamically so it looks exactly as if you had manually defined it on your page.
    DD Admin

  3. #3
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile

    Great! That worked like a charm, thank you. Are there any issues that you can think of with moving the php database connection script which previously lived in the beginning of the <body> section to the <head> section (to allow for this code to run?)
    Thank you
    Mitch

  4. #4
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Not that I can think of, no. The code for DB connections is server side, hence it makes no difference where it appears on the page, as it's always executed first before the page itself is rendered and output to the browser. But in this case since we want the output of the db connection to be within the HEAD section of the page, that's where your code should be at.
    DD Admin

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •