user295284
user295284

Reputation: 367

Changing the status of a field in PHP after a period of time

For example I made a reservation for a restaurant and it expires in 24 hours. In the reservation table of the db (MySQL), how do I automatically update the status to expired after 24 hours? What approach would you guys suggest? Thanks in advance!

Upvotes: 0

Views: 2481

Answers (5)

satya
satya

Reputation: 1959

I would suggest the following two methods.

  1. To run a cookie at the background and check it out if the time (here in this case 24hrs) ran out or not..
  2. Store the entry in the database with DATETIME type. As we check whether the user logged in or not with session variables. In the similar way for every click in the site, call a function to check whether the time is lapsed or not.

Upvotes: 0

vikas
vikas

Reputation: 1

using cron can be liitle difficult

just run update query by comparing timestamp value with your time limit.

it will work.

Upvotes: 0

Piotr Pankowski
Piotr Pankowski

Reputation: 2406

Use cron like Unreason said or MySQL events, see Create event.

Upvotes: 1

Gunjan
Gunjan

Reputation: 1237

Don't really know the problem you're trying to handle but I'd store the timestamp when the reservation was made and have a field which stores after what interval from the point reservation was made does it expire (24 hrs in your case) and that's it. The rest should be handled at the point where you read/display that information.

Besides if you still really want to CHANGE the value in DB go for a cron that regularly updates the DB

Upvotes: 7

Unreason
Unreason

Reputation: 12704

Running periodical tasks is usually done with cron.

Here are some instructions how to use it on drupal (which is php/mysql)

Upvotes: 1

Related Questions