WebCheez Posted May 30, 2011 Share Posted May 30, 2011 How would I make a script that would delete any row in a MySQL table that was more than 7 days old? Quote Link to comment https://forums.phpfreaks.com/topic/237921-deleting-old-mysql-rows/ Share on other sites More sharing options...
mikesta707 Posted May 30, 2011 Share Posted May 30, 2011 do you have a column in your table that is a timestamp of when the row was entered? if so is it a date or datetime type? Quote Link to comment https://forums.phpfreaks.com/topic/237921-deleting-old-mysql-rows/#findComment-1222591 Share on other sites More sharing options...
WebCheez Posted May 30, 2011 Author Share Posted May 30, 2011 Nope. *goes to create one* Quote Link to comment https://forums.phpfreaks.com/topic/237921-deleting-old-mysql-rows/#findComment-1222602 Share on other sites More sharing options...
WebCheez Posted May 30, 2011 Author Share Posted May 30, 2011 So once I have that, what do I do? Quote Link to comment https://forums.phpfreaks.com/topic/237921-deleting-old-mysql-rows/#findComment-1222606 Share on other sites More sharing options...
Drummin Posted May 30, 2011 Share Posted May 30, 2011 Something like this $timeoutseconds = 604 800; //get the time $timestamp = time(); $timeout = $timestamp-$timeoutseconds; $delete = mysql_query("DELETE FROM mytable WHERE timestamp<$timeout"); Quote Link to comment https://forums.phpfreaks.com/topic/237921-deleting-old-mysql-rows/#findComment-1222613 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.