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

Recommended Answers

All 2 Replies

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.

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.