Results 1 to 3 of 3

Thread: deleting loop through mysql db

  1. #1
    Join Date
    Jun 2004
    4846′36″ N 910′48″ E

    deleting loop through mysql db

    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

  2. #2
    Join Date
    Aug 2004
    DELETE FROM table_name WHERE activated = 0 AND
    (CAST(UNIX_TIMESTAMP() AS SIGNED) - CAST(date_reg AS SIGNED)) > 604800;
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

  3. #3
    Join Date
    Jun 2004
    4846′36″ N 910′48″ E

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles