Page 1 of 1
php help
Posted: Thu Mar 19, 2009 2:50 pm
by flemingmike
hi, i was wondering if anyone had a code that i could have for when a database entry gets entered, it will remove itself after 3 hours?
i have a page where someone creates a question and it currently takes a timestamp. i would like to put in my page where you view the questions the code to check all timestamps in the table, and remove any that are older than 3 hours.
table is called 'findamatch' table is called 'timestamp'
thanks.
Re: php code for database entry - time to live
Posted: Thu Mar 19, 2009 3:02 pm
by flemingmike
does this work?
Code: Select all
SELECT * FROM findamatch WHERE `timestamp` > NOW() - INTERVAL 3 HOUR
Re: php help
Posted: Thu Mar 19, 2009 3:15 pm
by flemingmike
nope, doesnt remove it from database... hmmm how about:
Code: Select all
if($timestamp < NOW() - INTERVAL 3 HOUR){
remove from database code??
}
Re: php help
Posted: Thu Mar 19, 2009 3:21 pm
by Eran
Code: Select all
DELETE FROM `findamatch` WHERE `timestamp` < NOW() - (3 * 3600)
Re: php help
Posted: Thu Mar 19, 2009 3:21 pm
by flemingmike
thank you much
Re: php help
Posted: Thu Mar 19, 2009 3:36 pm
by flemingmike
didnt work.
i tried this:
Code: Select all
$fam=mysql_query("SELECT id,clan,rules,month,day4,year,hour,min,ampm,timezone,teamid,ladder,maxbet,aim,email,yim,timestamp FROM findamatch ORDER BY timestamp");
while(list($id,$clan,$rules,$month,$day4,$year,$hour,$min,$ampm,$timezone,$teamid,$ladder,$maxbet,$aim,$email,$yim,$timestamp)=mysql_fetch_row($fam)){
$deleterow=$timestamp;
mysql_query("DELETE FROM findamatch WHERE NOW() - 25 MINUTE > '$deleterow'");