Jnerocorp Posted September 27, 2009 Share Posted September 27, 2009 Do you know how to make it so after information is put into a database it is set to delete itself from the database after 10 minutes? Quote Link to comment https://forums.phpfreaks.com/topic/175707-help-auto-deleting-row-from-table-after-x-ammount-of-time/ Share on other sites More sharing options...
Alex Posted September 27, 2009 Share Posted September 27, 2009 You could create a row to store a UNIX time stamp on each record then run a CRON job every X minutes to check and see if that time stamp is older than 10 minutes. Quote Link to comment https://forums.phpfreaks.com/topic/175707-help-auto-deleting-row-from-table-after-x-ammount-of-time/#findComment-925906 Share on other sites More sharing options...
Jnerocorp Posted September 27, 2009 Author Share Posted September 27, 2009 I will try that but what would the cron job command be the file will be called cron.php and what would i put in the file cron.php that would delete all the old data Quote Link to comment https://forums.phpfreaks.com/topic/175707-help-auto-deleting-row-from-table-after-x-ammount-of-time/#findComment-925910 Share on other sites More sharing options...
RichardRotterdam Posted September 27, 2009 Share Posted September 27, 2009 I will try that but what would the cron job command be the file will be called cron.php What do you mean with that sentence? and what would i put in the file cron.php that would delete all the old data This is where you write a delete query which deletes records older then 10 minutes. Quote Link to comment https://forums.phpfreaks.com/topic/175707-help-auto-deleting-row-from-table-after-x-ammount-of-time/#findComment-925918 Share on other sites More sharing options...
Jnerocorp Posted September 27, 2009 Author Share Posted September 27, 2009 I will try that but what would the cron job command be? The file will be called cron.php I dont know what the query would be to delete when 10 minutes old Quote Link to comment https://forums.phpfreaks.com/topic/175707-help-auto-deleting-row-from-table-after-x-ammount-of-time/#findComment-925922 Share on other sites More sharing options...
RichardRotterdam Posted September 27, 2009 Share Posted September 27, 2009 http://lmgtfy.com/?q=delete+query+mysql Quote Link to comment https://forums.phpfreaks.com/topic/175707-help-auto-deleting-row-from-table-after-x-ammount-of-time/#findComment-925924 Share on other sites More sharing options...
Jnerocorp Posted September 27, 2009 Author Share Posted September 27, 2009 no i mean i dont know how to delete a query if its 10 minutes old I dont now the commands that it takes to check if any rows in the table are 10 minutes old and to delete them if they are Quote Link to comment https://forums.phpfreaks.com/topic/175707-help-auto-deleting-row-from-table-after-x-ammount-of-time/#findComment-925929 Share on other sites More sharing options...
RichardRotterdam Posted September 27, 2009 Share Posted September 27, 2009 Well what do you go so far? Quote Link to comment https://forums.phpfreaks.com/topic/175707-help-auto-deleting-row-from-table-after-x-ammount-of-time/#findComment-925936 Share on other sites More sharing options...
Jnerocorp Posted September 27, 2009 Author Share Posted September 27, 2009 I dont thats the problem i dont know how to delete querys after a specific time Quote Link to comment https://forums.phpfreaks.com/topic/175707-help-auto-deleting-row-from-table-after-x-ammount-of-time/#findComment-925942 Share on other sites More sharing options...
RichardRotterdam Posted September 27, 2009 Share Posted September 27, 2009 Before you can delete something from a database there should be something in it. Do you have that part? Other then that in your title description you mention you want to delete rows, but now your asking to delete queries? I think you had it right the first time. Quote Link to comment https://forums.phpfreaks.com/topic/175707-help-auto-deleting-row-from-table-after-x-ammount-of-time/#findComment-925949 Share on other sites More sharing options...
Alex Posted September 27, 2009 Share Posted September 27, 2009 Assuming your unix time stamp field is called time_created you can do this: mysql_query("DELETE FROM `table` WHERE time_created + 600 <= UNIX_TIMESTAMP()"); Quote Link to comment https://forums.phpfreaks.com/topic/175707-help-auto-deleting-row-from-table-after-x-ammount-of-time/#findComment-925967 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.