Side
Side

Reputation: 1751

Run a MySQL query if a week has passed

First of all I am a beginner, and I don't want anybody to write code for me. I would just like a bit of a hint from a more experienced developer.

I have a video site, what loads videos from another website with XML and saves info about the videos in the database. What I would like to do is that if a week is passed, automatically run the insert query.

I never did this before and never worked with time functions like this. So please could someone show his plan how he would do it? So no code, just explain the process.

Upvotes: 0

Views: 176

Answers (5)

Benjamin Netter
Benjamin Netter

Reputation: 1551

You can use the time() function. It returns the number of seconds since January, 1st, 1970.

Then, for example, you take the time at t = 0. When time() - t > a week (= 3600 * 24 * 7 seconds), you know a week has passed by.

Upvotes: 0

CodeCaster
CodeCaster

Reputation: 151654

What do you want to do with the data in the week in between? I hope you're not hoping to keep a process running for a week and then execute the insert.

You could do something like load the XML and save it in the database, setting an active column to 0. You save the timestamp at the moment the insert is executed.

Meanwhile, using cron, you let a script run every X minutes or hours, checking the database for items that have been inactive for a week, and then updating them to become active.

Upvotes: 1

str
str

Reputation: 44979

You could use Cronjobs.

Upvotes: 1

SeanCannon
SeanCannon

Reputation: 77996

I'd recommend setting up a cron: http://en.wikipedia.org/wiki/Cron

Upvotes: 5

DarkBee
DarkBee

Reputation: 15625

I dont think this is a coding-related problem. Tasking can be achieved by using cron. Cron is a task scheduler, which when its available for your hosting, can be accessed at the hosting control panel. What is your host ?

Upvotes: 1

Related Questions