Jump to content

Eliminate MySQL Entry based on date


inquisitive

Recommended Posts

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????

Link to comment
Share on other sites

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 ;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.