0

I have a button that I would like to increase a number by 1 and reload the page when clicked. If the user navigates away from the page and then comes back i would like the number to be reset to 0.

any ideas how this happens?

2 Answers 2

1

So, here's how you could do it if you're wanting to change up what image is displayed. Pretend this url is your page: http://someserver.com/photo_page.php?photo_id=1

The photo id is the thing you're wanting to increment. You can get at this via the $_GET superglobal.

So, quick off the top of my head example:

$my_var = $_GET['photo_id'];
$next_photo = $my_var + 1;
$the_link_i_want_to_make_my_button = 'http://someserver.com/photo_page.php?photo_id='. $next_photo;

You'd then put that link as what your next button does, and you would default it to 1 or whatever you want if empty($_GET['photo_id']).

Also probably want to make sure that you handle people putting silly numbers in there like 9000 if you have over 9000 images, etc.

I think this'll get you close?

Sign up to request clarification or add additional context in comments.

2 Comments

What i want to do is, currently my page displays an image retrieved from a database when the user clicks the next button i need it to increase a number which corresponds to the number currently being displayed. basically so a new image is displayed
Oh, so this is like a photo gallery? Why don't you just store the id as part of the URL? I'll edit the previous with an example.
0

Why can't you just increment it after the page reload? If it absolutely has to be done, you would have to do it with an AJAX call.

2 Comments

I would like the variable to be reset if the user navigates away from the page and the process starts again if they come back and press the link
Button (html input or button element) != link (html hyperlink). Which is it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.