Delete from database if past date

Discussion in 'PHP' started by wvccboy, Feb 18, 2008.

  1. #1
    Here's what I have:

    $date = EXPIRATION DATE (from DB);
    $today = date("m/d/y");

    If today is past the expiration date which is listed, it removes it from the database.

    How can I set this up?

    Thanks
     
    wvccboy, Feb 18, 2008 IP
  2. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    selling vcc, Feb 18, 2008 IP
  3. Chuckun

    Chuckun Well-Known Member

    Messages:
    1,161
    Likes Received:
    60
    Best Answers:
    2
    Trophy Points:
    150
    #3
    You could simply use:

    if $date = $today {
    mysql_query('TRUNCATE TABLE tbl_name') 
    or die(mysql_error());  
    }
    PHP:
    I think..?

    It's been a long time since i've coded anything to be honest =[

    Chuckun
     
    Chuckun, Feb 18, 2008 IP
  4. wvccboy

    wvccboy Notable Member

    Messages:
    2,632
    Likes Received:
    81
    Best Answers:
    1
    Trophy Points:
    250
    #4
    I could use Cronjobs but how could I set it up?

    Thanks Chuckun but if $date = $today isn't exactly right since it's on the POST page, where if the posted date is before today it'd also return an error and delete it.
     
    wvccboy, Feb 18, 2008 IP
  5. Chuckun

    Chuckun Well-Known Member

    Messages:
    1,161
    Likes Received:
    60
    Best Answers:
    2
    Trophy Points:
    150
    #5
    Dont quite follow you but okeyyy :L

    Sorry
    Chuckun
     
    Chuckun, Feb 18, 2008 IP
  6. decepti0n

    decepti0n Peon

    Messages:
    519
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #6
    if ($date < time()) {
        // delete
    }
    
    if (strtotime($date) < time()) {
        // delete
    }
    
    PHP:
    First one if the date in the db is a timestamp, second one if its something like 08-08-2000 02:34:06
     
    decepti0n, Feb 18, 2008 IP
    wvccboy likes this.
  7. wvccboy

    wvccboy Notable Member

    Messages:
    2,632
    Likes Received:
    81
    Best Answers:
    1
    Trophy Points:
    250
    #7
    Thanks decepti0n. Rep added.

    Now another question.

    Once the thing goes out of date, it needs to be removed once a script is run and delete from MySQL.

    How's a good way to do it?

    Thanks!
     
    wvccboy, Feb 18, 2008 IP
  8. NathanH

    NathanH Peon

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Instead of a cron job, you could simply have the code run each time a page is loaded. Have it check the date and delete any rows from the database which have expired. Or, even better - you could use a few lines of code so the script is only executed once a day (Saves from having to setup the cron jobs)
     
    NathanH, Feb 18, 2008 IP