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'");

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.