inquisitive Posted August 22, 2008 Share Posted August 22, 2008 Alright here is what I am trying to do I have a website where users login and submit items for sale... I approve them and then their item goes into a list on the index.php page of items for sale... Now I was stupid and didn't program a way to delete them and there are tons of entries now... In order to remedy this situation I would like to program a script that eliminates the entries in the database after they have been in the database for 2 weeks...anyone have any idea how to do this???? Quote Link to comment Share on other sites More sharing options...
obsidian Posted August 22, 2008 Share Posted August 22, 2008 Run a cron job with the following query: DELETE FROM entry_table WHERE entry_date < CURDATE() - INTERVAL 2 WEEK; Quote Link to comment Share on other sites More sharing options...
inquisitive Posted August 22, 2008 Author Share Posted August 22, 2008 So just this one line of code does it? DELETE FROM entry_table WHERE entry_date < CURDATE() - INTERVAL 2 WEEK; Quote Link to comment Share on other sites More sharing options...
Hooker Posted August 23, 2008 Share Posted August 23, 2008 If you're using mysql 5.0 or above and want to clean the records automaticaly, you can use something like this: To enable the event scheduler: SET GLOBAL event_scheduler = 1; To trigger to stored procedure every 60 minutes: CREATE EVENT clean ON SCHEDULE EVERY 60 MINUTE COMMENT 'Clean old data.' DO CALL cleandata(); To run the clean-up command: DELIMITER $$ DROP PROCEDURE IF EXISTS `cleandata` $$ CREATE PROCEDURE `cleandata`() BEGIN DELETE FROM entry_table WHERE entry_date < CURDATE() - INTERVAL 2 WEEK; END $$ DELIMITER ; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.