Jump to content


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


Auto Delete Script

Recommended Posts


I wrote a script to check the date of a link, find how old it is, then if it is older then the said max date, delete it. But I cannot figure how to have it delete it... on its own...

$query=("SELECT * FROM archive ORDER BY link_id DESC");
$row = mysql_fetch_row($result);

$link_id = $row[0];

$curmonth = date('m-d-Y') + 0; //Find out the current month
$monthchange = $link_date + 0; //Find out the month of the link
$month = $curmonth - $monthchange; //Find the month offset

if($month < 2){ //Do nothing if link is less then 2 months old
        } if($month == 2){ //Do nothing if link is 2 months old
        }if($month > 2){ //Start deletion process if link is older then 2 months
//Here is where i tell it to auto-delete the link..

I don't know what to put to make it auto-delete it. I have a delete script set up to run of link_id. Can you help me please?

Share this post

Link to post
Share on other sites
I can't see how you are retrieving $link_date, but if it is stored as a UNIX timestamp, you can work that out with:

[code]$limit = time() - 5184000;
if ($link_date < $limit) {
   // too old...
} else {
   // do something else...

5184000 = 60 days = 60 * 60 * 24 * 30

Now, 60 days isn't exactly 2 months but it's pretty close to it. If you want a more exact calculation, it's a bit more of work, but I don't like it [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]

Share this post

Link to post
Share on other sites
When you add + 0 to the date in $curmonth it will show only the month. now i can take the current month which is 6, take the month of the link which is 3, find out the difference which is 3. Now that i know the link is three months old. I need to have it delete it.

My problem is not with how I have the date setup, that is fine. My problem is i dont know how to make it auto-delete it.

Like i said before, i have a delete script that is setup to run off $link_id. So if i tell it to delete link_id=17 it will delete the 17th link...

So again my question is. What can I use to make it delete the link when it hits age?

Share this post

Link to post
Share on other sites


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.