0

Hi
I want to ask question in loop everytime there is two button in the question one is for download image and the other is next if user click on download the image download and next itration start and if the user click on next button the next itration start. How i can do this ?? waiting for your reply

Thanks

3
Contributors
2
Replies
5
Views
4 Years
Discussion Span
Last Post by diafol
0

PHP is server-side and as such does not have user interaction. You will need to make a script that outputs a form for the first image. When the form is submitted do the next. You can use a session to store the current image being processed.

0

You could do straight js solution, where on page load you get all the id values and image data to iterate through in json format (js variable).
Then when you click next it advances to the next item - i.e. overwrite the img src property button and some property of the 'download' button. This way you don't need to send to the server every time.

This doesn't depend on ajax.

page.php

DB routine - create array in while loop:

...while...
$image_data['id'][] = $row['id'];
$image_data['filename'][] = $path . '/' . $row['filename'];
..end while...

$r = json_encode($image_data);
...

<form ...>
    <img id="theimage" src="<?php echo $image_data['filename'][0];?>" />
    <button id="next">Next</button>
</form>

<!-- at bottom of page you can use vanilla js instead of jquery though-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
    var counter =0;
    var json = <?php echo $r;?>; //can't remember if you need a ; here
    ...
    $('#next').click(function(e){
        e.preventDefault();
        counter++;
        $('#theimage').attr('src',json['filename'][counter]);
    });
</script>

Not tested, just an idea. Thrown down quickly.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.