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.
php help
Moderator: General Moderators
-
flemingmike
- Forum Newbie
- Posts: 17
- Joined: Wed Mar 18, 2009 5:29 pm
php help
Last edited by flemingmike on Thu Mar 19, 2009 3:11 pm, edited 1 time in total.
-
flemingmike
- Forum Newbie
- Posts: 17
- Joined: Wed Mar 18, 2009 5:29 pm
Re: php code for database entry - time to live
does this work?
Code: Select all
SELECT * FROM findamatch WHERE `timestamp` > NOW() - INTERVAL 3 HOUR-
flemingmike
- Forum Newbie
- Posts: 17
- Joined: Wed Mar 18, 2009 5:29 pm
Re: php help
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
Code: Select all
DELETE FROM `findamatch` WHERE `timestamp` < NOW() - (3 * 3600)-
flemingmike
- Forum Newbie
- Posts: 17
- Joined: Wed Mar 18, 2009 5:29 pm
Re: php help
didnt work.
i tried this:
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'");