Jump to content

Auto Delete Script


lice200

Recommended Posts

Hey,

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

[code]<?php
$query=("SELECT * FROM archive ORDER BY link_id DESC");
$result=mysql_query($query);
$row = mysql_fetch_row($result);

$link_id = $row[0];
mysql_close();

$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..
}
?>[/code]

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?
Link to comment
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...
}[/code]

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\" /]
Link to comment
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?
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.