SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,099
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Echo within javascript function

    For a website I am working on I use the jQuery Supersized full sreen slideshow. In the Supersized function the images are hard coded:
    Code:
    <script type="text/javascript">
      jQuery(function($){
        $.supersized({
          slide_interval    :   3000,		
          transition        :      1, 	
          transition_speed:	  1000,	
          slides:   [			
                               {image : 'page_backgrounds/home1.jpg'},
    			   {image : 'page_backgrounds/home2.jpg'},  
                               {image : 'page_backgrounds/home3.jpg'},
                               {image : 'page_backgrounds/home4.jpg'},
    			   {image : 'page_backgrounds/home5.jpg'},
    												    ]
        });
      });
    </script>
    But I actually would like to echo them within the function since the images I am going to use will come from the database:
    Code:
    $query = "
                  SELECT
                                  *
                  FROM
                                  page_backgrounds
                 ORDER
                  BY	      sort_order";
    How can I use PHP within the above function?

    Thank you in advance!
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2013
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use AJAX to get them or if the javascript is within the php script you can just loop through each image and echo it out like you would any other variable.

  3. #3
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by donboe View Post
    For a website I am working on I use the jQuery Supersized full sreen slideshow. In the Supersized function the images are hard coded:
    Code:
    <script type="text/javascript">
      jQuery(function($){
        $.supersized({
          slide_interval    :   3000,        
          transition        :      1,     
          transition_speed:      1000,    
          slides:   [            
    <?php //Loop through query results
    while $res=......depends on method being used
    $query_result=$res['Image'];
    $image="                           {image : '".$query_result."'}";
    echo $image;
    ?>
                        ]
        });
      });
    </script>
    I have edited your code to give an example of what was meant about writing the images into the JQuery array.
    Ian Anderson
    www.siteguru.co.uk

  4. #4
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,099
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    while $res=......depends on method being used
    Hi thank you for the response. I am not completely sure what you mean with the above?.
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)


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
  •