on click of a link increment php variable
I have a button that I would like to increase a number by 1 and reload the page when clicked. If the 开发者_StackOverflowuser navigates away from the page and then comes back i would like the number to be reset to 0.
any ideas how this happens?
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?
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.
精彩评论