I’m trying to use strtotime() to respond to a button click to advance -1 and +1 days (two buttons) relative to the day advanced to on the previous click.
Example:
- It’s the 10th of the month, I click ‘-1 day’ button, and now the date reads as the 9th.
- I click the ‘-1 day’ button again and now the readout states the 8th day.
- I click the ‘+1 day’ button and now the readout states it’s the 9th.
I understand the buttons and the displaying the date and using $_GET and PHP to pass info, but how do I get strtotime() to work on the relative date from the last time the time travel script was called?
My work so far has let me show yesterday and today relative to now but not relative to, for example, the day before yesterday, or the day after tomorrow. Or if I use my ‘last monday’ button, the day before or after whatever that day is.
Working from previous calls to the same script isn’t really a good idea for this type of thing.
What you want to do is always pass two values to your script, the date, and the movement. (the below example is simplified so that you only pass the date, and it will always add one day to it)
Example
http://www.site.com/addOneDay.php?date=1999-12-31
Please note that you should check to make sure that isset($_GET[date]) before as well
If you really want to work from previous calls to the same script, you’re going to have to do it with sessions, so please specify if that is the case.