Click to See Complete Forum and Search --> : urgent - auto delete
XeroSiS
05-21-2006, 01:42 AM
I have records in my table which one is date of post, and also I have a section where it asks the user how many day does he wants this record to be inside the website, giving it the following list: 1 day, 5 days, 1 month, 6 months, 1 year.
I need these records to automatically get deleted once they pass the given day.
XeroSiS
05-21-2006, 02:38 AM
hello!? nobody can help me?
Kethinov
05-21-2006, 02:39 AM
Assuming you're using a Linux or UNIX-like web server and have shell access, you can setup a cronjob to run a PHP script once a day to weed out the old records.
Or you can simply not display records that are of a certain age on all your PHP scripts. Depends on what solution works best for you.
XeroSiS
05-21-2006, 03:53 AM
yeah but how can I check to see how many days have passed from when my record was posted! ... for example it saves 12/04/06 ... do I have to take todays date, explode it and ... you know what Im saying?? isnt there an easier way? to check once todays date and compare it with the dop? the best solution for me is:
todays date - date of post = a specific number (for example 2 months will be 60)
Kethinov
05-21-2006, 04:11 AM
Loop through the posts.
$time_since = time() - $yourdate;
if ($time_since > a certain number) mysql_query("DELETE FROM etc");
This assumes your dates are stored as unix timestamps. If not, try using strtotime() on them to get a timestamp.
These timestamps are measured in seconds, so do the math.