Jump to content


Auto Delete Script

  • Please log in to reply
2 replies to this topic

#1 lice200

  • Members
  • PipPip
  • Member
  • 24 posts

Posted 12 June 2006 - 06:50 PM


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?

#2 poirot

  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 12 June 2006 - 06:56 PM

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:

$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\" /]
~ D Kuang

#3 lice200

  • Members
  • PipPip
  • Member
  • 24 posts

Posted 12 June 2006 - 07:33 PM

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?

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users