spikypunker Posted May 8, 2009 Share Posted May 8, 2009 Hey duuudes, i've got a mysql which holds an events section of my site, at the moment i log in each day and delete all entries with a date older than the current date, but yeah, i need this to be automatic really. I've set up a CRON on the server, which runs cron.php at 3 in the morning each day. In this php page i've got the following code.... <? $date = date("Y-m-d"); mysql_connect ("localhost","###","###"); @mysql_select_db("###") or die ("unable to connect"); $query = "DELETE FROM events_backup WHERE 'date' < $date ;"; $result = mysql_query($query); mysql_close(); echo "$date "; ?> I thought this would be fairly simple but alas, i've tried it on my back up table (events_backup) and it deleted all the data! poo Link to comment https://forums.phpfreaks.com/topic/157359-solved-delete-rows-older-than-the-current-day/ Share on other sites More sharing options...
GingerRobot Posted May 8, 2009 Share Posted May 8, 2009 You've put single quotes around your field name. Therefore, it's treated as a string. Lexicographically, 'date' must be less than any number, therefore, it's deleting all the rows since it's true for all rows. Link to comment https://forums.phpfreaks.com/topic/157359-solved-delete-rows-older-than-the-current-day/#findComment-829428 Share on other sites More sharing options...
spikypunker Posted May 8, 2009 Author Share Posted May 8, 2009 haha my fault, simple error, should have checked! <? $date = date("Y-m-d"); mysql_connect ("localhost","maddogma_listing","mightyb00sh"); @mysql_select_db("maddogma_listings") or die ("unable to connect"); $query = "DELETE FROM events WHERE date < '$date' ;"; $result = mysql_query($query); mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/157359-solved-delete-rows-older-than-the-current-day/#findComment-829542 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.