Delete old records (30 days)

  • BooGiE_MaN
  • Proficient
  • Proficient
  • User avatar
  • Posts: 387
  • Loc: Cape Town, South Africa

Post 3+ Months Ago

Im trying to create a function to delete old records
I have
PHP Code: [ Select ]
mysql_query("delete from linkhits where date < DATE_SUB(CURDATE(),INTERVAL 30 DAY)")
but it deletes all records.. whats missing?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • onlyican.com
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1589
  • Loc: Hants, UK

Post 3+ Months Ago

use php to work out the date minus 1 month

Then run the query

DELETE FROM linkhits WHERE date_row < '".$date_minus_one_month."'

Also note

Date is a pre-defined word in MySQL, and you can not call a column date
  • BooGiE_MaN
  • Proficient
  • Proficient
  • User avatar
  • Posts: 387
  • Loc: Cape Town, South Africa

Post 3+ Months Ago

Aha.
What are the other things you can not call a column?
I already now of "default", "option" and "order"; unless you use `default`... anyone know of any others?
  • onlyican.com
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1589
  • Loc: Hants, UK

Post 3+ Months Ago

A quick search on google reveals all

http://dev.mysql.com/doc/refman/5.0/en/ ... words.html
  • Dr_brew
  • Novice
  • Novice
  • Dr_brew
  • Posts: 20

Post 3+ Months Ago

You can use them, you just have to put quotes around it.

You could use:
Code: [ Select ]
<?php
   $date = time() - 60*60*24*30; // 30 days ago
   mysql_query("DELETE FROM linkhits WHERE `date` < {$date}");
?>
  1. <?php
  2.    $date = time() - 60*60*24*30; // 30 days ago
  3.    mysql_query("DELETE FROM linkhits WHERE `date` < {$date}");
  4. ?>
  • BooGiE_MaN
  • Proficient
  • Proficient
  • User avatar
  • Posts: 387
  • Loc: Cape Town, South Africa

Post 3+ Months Ago

Thanks Doc!

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 126 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.