FarhanKhalaf Posted May 6, 2009 Share Posted May 6, 2009 I have a table nordstromlisting with column datecreated filled with a unix timestamp of when the listing was created. I essentially want to delete all listings older than 5 days (432000 seconds), so I created the following sql. However, it's not working. Anybody see what I'm doing wrong? Thanks. $timenow = date("Y-m-d"); $time = strtotime($timenow); $movetohistory = mysql_query("SELECT * INTO nordstromhistory FROM nordstromlisting WHERE '$time' - datecreated > 432000"); $deltefromlisting = mysql_query("DELETE * FROM nordstromlisting WHERE '$time' - datecreated > 432000"); Link to comment https://forums.phpfreaks.com/topic/157031-solved-date-problem/ Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 There's no such thing as SELECT * INTO .... At least I don't think so. Change this: $movetohistory = mysql_query("SELECT * INTO nordstromhistory FROM nordstromlisting WHERE '$time' - datecreated > 432000"); To: $movetohistory = mysql_query("SELECT * INTO nordstromhistory FROM nordstromlisting WHERE '$time' - datecreated > 432000") or die(mysql_error()); That should display some error if there is one. Link to comment https://forums.phpfreaks.com/topic/157031-solved-date-problem/#findComment-827278 Share on other sites More sharing options...
FarhanKhalaf Posted May 6, 2009 Author Share Posted May 6, 2009 You're right, the syntax is messed up becuase for one INTO doesn't show up in the proper color, and the error it gives me is 'undefined variable: nordstromhistory' However, the w3 http://www.w3schools.com/sql/sql_select_into.asp does it that way? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/157031-solved-date-problem/#findComment-827296 Share on other sites More sharing options...
Mchl Posted May 6, 2009 Share Posted May 6, 2009 Just read what you've written in your first post. You want to DELETE rows, so you should use DELETE query. SELECT .. INTO is used for moving data from one table to another. Link to comment https://forums.phpfreaks.com/topic/157031-solved-date-problem/#findComment-827299 Share on other sites More sharing options...
FarhanKhalaf Posted May 6, 2009 Author Share Posted May 6, 2009 Excuse me, I should of clarified better: I want to MOVE listings older than 5 days into nordstromhistory, AND delete them from nordstromlisting. Sorry about that. Link to comment https://forums.phpfreaks.com/topic/157031-solved-date-problem/#findComment-827300 Share on other sites More sharing options...
Mchl Posted May 6, 2009 Share Posted May 6, 2009 Heh... yeah... I should've noticed that. Too quick to reply too early in the morning Ok... so is any of your queries working, or do both of them fail? Link to comment https://forums.phpfreaks.com/topic/157031-solved-date-problem/#findComment-827303 Share on other sites More sharing options...
FarhanKhalaf Posted May 6, 2009 Author Share Posted May 6, 2009 Only the first one fails other one doesn't give an error. Link to comment https://forums.phpfreaks.com/topic/157031-solved-date-problem/#findComment-827307 Share on other sites More sharing options...
Mchl Posted May 6, 2009 Share Posted May 6, 2009 A strange bit is that ''undefined variable: nordstromhistory'' is a PHP notice, not a MySQL error... Is that all you get? [edit] Seems I was wrong about what SELECT INTO is about http://dev.mysql.com/doc/refman/5.0/en/select-into-statement.html What you need is INSERT ... SELECT INSERT INTO nordstromhistory SELECT ... FROM nordstromlisting WHERE '$time' - datecreated > 432000 http://dev.mysql.com/doc/refman/5.1/en/insert-select.html Link to comment https://forums.phpfreaks.com/topic/157031-solved-date-problem/#findComment-827308 Share on other sites More sharing options...
FarhanKhalaf Posted May 6, 2009 Author Share Posted May 6, 2009 Yep :-\ Link to comment https://forums.phpfreaks.com/topic/157031-solved-date-problem/#findComment-827313 Share on other sites More sharing options...
FarhanKhalaf Posted May 6, 2009 Author Share Posted May 6, 2009 I tried $movetohistory = mysql_query("INSERT INTO nordstromhistory SELECT * FROM nordstromlisting WHERE '$time' - datecreated > 432000") or die(mysql_error()); and got the following error: Duplicate entry '1' for key 1 hmm... Link to comment https://forums.phpfreaks.com/topic/157031-solved-date-problem/#findComment-827316 Share on other sites More sharing options...
Mchl Posted May 6, 2009 Share Posted May 6, 2009 Probably a conflict in primary keys of both tables. That's why you should explicitly state which columns you're moving. Or you can use ON DUPLICATE KEY UPDATE Link to comment https://forums.phpfreaks.com/topic/157031-solved-date-problem/#findComment-827317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.