php help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
flemingmike
Forum Newbie
Posts: 17
Joined: Wed Mar 18, 2009 5:29 pm

php help

Post 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.
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

Post by flemingmike »

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

Post by flemingmike »

nope, doesnt remove it from database... hmmm how about:

Code: Select all

 
if($timestamp < NOW() - INTERVAL 3 HOUR){
 
remove from database code??
 
}
 
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: php help

Post by Eran »

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

Post by flemingmike »

thank you much
flemingmike
Forum Newbie
Posts: 17
Joined: Wed Mar 18, 2009 5:29 pm

Re: php help

Post 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'");
Post Reply