SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using PHP with javascript slideshow

    I'm trying to set up a Javascript slideshow but with images that are pulled from a mYSQL database using PHP.

    For example:

    PHP Code:
    if (!empty($row['pic1']))
    {
    echo 
    '<td><a href="images/carpictures/' $title16 '"><img src="images/carpictures/' $title16 '"  width="140" height="93"></a></td>';

    - and so on, with a statement testing to see if an image exists in that field. If it does, it gets added to the page with all the images displayed as thumbnails.

    What I want is to have the images bring up their larger version when hovered over, and launch a slideshow with an autoplay feature as well as the usual back / next / play / stop controls etc.

    However all the slideshows I've seen (Javascript based) have the image names assigned manually to individual variables in the page header.

    The problem being that my images are being generated by the PHP call to the database.

    Anyone know how I can get a Javascript slideshow working within this context- or know of one which actually does work with PHP?

    (I was using Lightbox, which is great, except that the client doesn't like it so I can't use it...)

  2. #2
    SitePoint Zealot Jaanboy's Avatar
    Join Date
    Sep 2007
    Location
    UK
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure exactly what kind of script your after, but for the ones you've previously looked at, would it be possible to loop once in the header (to assign the variables) then loop again to display them?

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, only thing is I can't figure how the PHP variables for each of the image names, e.g $image1, $image2 can be embedded into the Javascript, so that when in the script you assign the image names, you can instead assign the PHP variable. the PHP variables won't be interpreted by the Javascript as far as I'm aware?

  4. #4
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is one thing, very important to understand.
    There are 2 sides if web-application, server side and client side.
    It is two completely different environments.
    PHP runs on the server side. And it never go to the client side, where javascript runs.
    The only connection between these 2 worlds is text. Just plain text.
    PHP can generate any text you wish. If you want some javascript program, you have to generate it using PHP.
    So
    I can't figure how the PHP variables can be embedded into the Javascript
    There is no way.
    You can't embed PHP into javascript. But you can generate javascript, with all it's variables.

    So, the only thing you need is some experience with PHP.
    And as soon you'll be able to produce this HTML code
    Code:
    <b>Hello Dolly</b>
    from this PHP code
    PHP Code:
    <?php
    $name
    ="Dolly";
    echo 
    "<b>Hello $name</b>";
    ?>
    you'll be able to produce any javascript you want.
    Because it is completely same way, to make something like
    PHP Code:
    <?php
    $name
    ="Dolly";
    echo 
    "var=\"$name\"";
    ?>
    So, first of all you ought to figure out which javascript code you want. Even hardcode it. Test it to proof it works well.
    And only then go for PHP to generate this text dynamically


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
  •