Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2013
    Thanked 2 Times in 2 Posts

    Display previous & Next image dynamicllay

    Hi to everyone, i am trying to display a 5 image initially

    - When the user clicks "next" i want to display next 5 image from database , vice-versa for "previous" button.i am trying with the following code but i can't able to retrieve the javascript variable to php.
    <script type="text/javascript">
      var current=5;
      function moveImage(direction){
       if(direction == "left"){
          loadImage( current - 5 );
         loadImage( current + 5 );
      function loadImage(id)
    <input type="button" name="previous" onClick="moveImage('left')";>
    <input type="button" name="previous" onClick="moveImage('right')";>
    - How to get the javascript value into mysql limit(5,$id),,,

    Please give any suggestion regarding this or any better solution than this to display "previous" & "Next" images dynamically.

  2. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Thanked 1,012 Times in 1,009 Posts
    This is a double post.
    Javascript is client side and PHP is server side. Either you set everything up in php or use use ajax.
    To set up in PHP you would have to make an array and populate it with all of your images. Maybe not the best approach.
    Better would be to use ajax http://www.w3schools.com/ajax/. Have the JS keep track of what is currently displayed and send the info to PHP which will get the next set.


    I don't store images in the database. I place them in a folder and store their addresses in the DB. If you make the image names sequential, like image_1.jpg and image_2.jpg, ETC. You could do it all in JS and just change the src of the img tag (s).
    Last edited by sunfighter; 12-19-2013 at 04:48 PM.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.


Tags for this Thread

Posting Permissions

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