how would I go about telling mysql to delete any row that is older than X amount of days? I currently have a database but the items on there I would like to clear within 3 days. The current format of the table has a date in the form of mm/dd/yyyy so lets say if I wanted to tell mysql that I wanted to delete a row I created 3 days ago how would i do that?
If your date column is a mysql date or timestamp type you can do something like this (assuming the tabe name is "thetable" and the date column is named "addDate"): DELETE FROM thetable WHERE TO_DAYS(addDate) <= TO_DAYS(NOW()) -3; However, if your date column is just a varchar or text field, this query won't help you.
Store a timestamp with 3 days added on in the database when you insert your records. Something like this would work.. $expires = time() + 259200; mysql_query("INSERT INTO table (expires) VALUES ('$expires')"); // then when you want to update and remove $time = time(); mysql_query("DELETE FROM table WHERE expires < '$time'"); PHP: Thats just a rough guide but thats how I would do it.