Click to See Complete Forum and Search --> : deleting loop through mysql db


LiLcRaZyFuZzY
01-18-2006, 02:01 AM
using MySQL:

I'm trying to write a query to delete old(1 week or more) unactivated dB entries
there is a field called "activated" which is boolean (0 for unactivated)
and a field called "date_reg" which is a unix timestamp.

i want to check if the difference of time between now and the date of registration is more than 604800 seconds (1 week), do i need to loop through each field and make a comparison (with PHP) or is there any faster way, like an in-query operation that i can do?

also is there a way to limit it, in case that in the future there are too many users, so it doesn't slow the PHP script too much..something like LIMIT?

thanks for reading, hope you can help

NogDog
01-18-2006, 02:33 AM
DELETE FROM table_name WHERE activated = 0 AND
(CAST(UNIX_TIMESTAMP() AS SIGNED) - CAST(date_reg AS SIGNED)) > 604800;

LiLcRaZyFuZzY
01-18-2006, 06:15 AM
thanks!