Jump to content

Auto delete row after 3days


Daguse

Recommended Posts

A number of years ago, around 2002 I believe, when I first got into PHP and I had my first webserver, there was a "crontab" file that could be modified and set to execute scripts at pre-determined intervals. I'm not sure if 'crontab' is obsolete now, you might want to do a google search.

 

Alternatively, you can add a 'timestamp' column to your table, and place the code below in a script that you know a user will execute - preferably in the page where you are inserting the values into the table. By the way, the number 259200 is the number of seconds in 3 days. "time" is the name I happened to choose for the timestamp column.

 

$timestamp = date(U);
$prevtime = $timestamp - 259200;
mysql_query("INSERT INTO table values ('$var1,'$var2',$timestamp)");
mysql_query("DELETE FROM table WHERE time < '$prevtime'");

you could use cron jobs (or cron tabs) for this. If you host doesn't support them you can use this website:

 

http://www.webcron.org/index.php?&lang=en

 

web cron allows you to run a script at a certain interval (once every hour to once every year), and it can be password protected.

 

(it works fine with my .htaccess password protected script)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.