Hi guys, I want to make a query that, when run, would clear entries more than an hour old. It uses some things that are new to me, so I'm not sure if it would work. Here is the code: $sql = "DELETE * FROM tokens WHERE setdate < DATE_SUB(NOW(), INTERVAL 1 HOUR)"; mysql_unbuffered_query($sql,$con) or die('Error:' . mysql_error . '<br />Error number:' . mysql_errno()); PHP: Also, would that work with this code to set new entries? $token = mt_rand(1000, 10000); $sql="INSERT INTO tokens (token, setdate) VALUES ('$token',now())"; mysql_unbuffered_query($sql,$con) or die('Error:' . mysql_error . '<br />Error number:' . mysql_errno()); PHP: Thanks, - Tony
I'm using this to select events which are in the future: WHERE TIMEDIFF(event.startdate,now()) > 0 so maybe you could use this to select the ones in the past: WHERE TIMEDIFF(event.startdate,now()) < 0
if setdate - timestamp DB field you can use WHERE setdate < 3600 if setdate - datetime you can use date_dub or another functions. Your query good, don't use field in MySQL function, you need isolate it, like in your query setdate < date_sub... etc. If you use field in MySQL function, index don't be used by this field, if you have it