Jump to content


Photo

Deleting a record based on the system date/time?


  • Please log in to reply
2 replies to this topic

#1 Solarpitch

Solarpitch
  • Members
  • PipPipPip
  • Advanced Member
  • 708 posts
  • LocationDublin, Ireland

Posted 29 October 2006 - 01:25 PM

Hey Guys ,

I have an application that involeves user's uploading an add to sell a product. The user gets to select whether they want the add to run online for..

1 day
3 days
5 days
1 week

Is there a way or some code that I can use that automically removes the add from the database, based on the system date and time?

So if user selects 1 day . . 24 hours from the time it was uploaded it will be automatically deleted or better still . .  deleted and stored in an admin table!

Cheers,
Gerard.
Welcome to 9AM Monday, the furthest point away from 5PM Friday.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 29 October 2006 - 01:54 PM

<?php

$period = 5;   // how many days

$expiry_date = date('Y-m-d', strtotime("+$period days"));
?>


Write the expiry date to the ad record.

To remove old records

mysql_query ("DELETE FROM ads WHERE expiry_date < CURDATE()");
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Solarpitch

Solarpitch
  • Members
  • PipPipPip
  • Advanced Member
  • 708 posts
  • LocationDublin, Ireland

Posted 29 October 2006 - 01:58 PM

Thats simple huh! lol . . brilliant . . thanks a mill! :)
Welcome to 9AM Monday, the furthest point away from 5PM Friday.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users