hellouthere Posted April 2, 2007 Share Posted April 2, 2007 This function and query should delete any records that are 30 minutes old... function DateAdd($interval, $number, $date) { $date_time_array = getdate($date); $hours = $date_time_array['hours']; $minutes = $date_time_array['minutes']; $seconds = $date_time_array['seconds']; $month = $date_time_array['mon']; $day = $date_time_array['mday']; $year = $date_time_array['year']; switch ($interval) { case 'y': case 'yyyy': $year+=$number; break; case 'q': $year+=($number*3); break; case 'm': $month+=$number; break; case 'd': case 'w': $day+=$number; break; case 'ww': $day+=($number*7); break; case 'h': $hours+=$number; break; case 'n': $minutes+=$number; break; case 's': $seconds+=$number; break; } $timestamp= mktime($hours,$minutes,$seconds,$month,$day,$year); return $timestamp; } $query = "DELETE FROM positions WHERE last_update <= ".date("Y-m-d H:i:s", DateAdd("n", -30, time())); i honestly didnt write all of it but helped... the script returns the error... You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '13:50:43' at line 1 Link to comment https://forums.phpfreaks.com/topic/45268-functionquery/ Share on other sites More sharing options...
trq Posted April 2, 2007 Share Posted April 2, 2007 Try... $query = "DELETE FROM positions WHERE last_update <= '".date("Y-m-d H:i:s", DateAdd("n", -30, time())."'"); Failing that, can you echo the $query variable and show us the output? Link to comment https://forums.phpfreaks.com/topic/45268-functionquery/#findComment-219783 Share on other sites More sharing options...
hellouthere Posted April 2, 2007 Author Share Posted April 2, 2007 same error... query output is: DELETE FROM positions WHERE last_update <= '2007-04-02 14:12:24 Link to comment https://forums.phpfreaks.com/topic/45268-functionquery/#findComment-219797 Share on other sites More sharing options...
trq Posted April 2, 2007 Share Posted April 2, 2007 Your misssing the closing ' Link to comment https://forums.phpfreaks.com/topic/45268-functionquery/#findComment-219803 Share on other sites More sharing options...
hellouthere Posted April 2, 2007 Author Share Posted April 2, 2007 surely ())."'"); is the closing ' ? Link to comment https://forums.phpfreaks.com/topic/45268-functionquery/#findComment-219809 Share on other sites More sharing options...
trq Posted April 2, 2007 Share Posted April 2, 2007 Well its not in your printed $query so I assumed you'd made a mistake. What does your printed $query actually look like? Link to comment https://forums.phpfreaks.com/topic/45268-functionquery/#findComment-219818 Share on other sites More sharing options...
hellouthere Posted April 2, 2007 Author Share Posted April 2, 2007 Query... $query = "DELETE FROM positions WHERE last_update <= '".date("Y-m-d H:i:s", DateAdd("n", -30, time())."'"); Output... DELETE FROM positions WHERE last_update <= '2007-04-02 15:26:24 Error... You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''2007-04-02 15:27:47' at line 1 Link to comment https://forums.phpfreaks.com/topic/45268-functionquery/#findComment-219838 Share on other sites More sharing options...
trq Posted April 2, 2007 Share Posted April 2, 2007 $query = "DELETE FROM positions WHERE last_update <= '".date("Y-m-d H:i:s", DateAdd("n", -30, time()))."'"; Link to comment https://forums.phpfreaks.com/topic/45268-functionquery/#findComment-219851 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.