Delete chatpost automatically.
Started on the old forum in June 2011 · view the original in the archive · old links redirect here
$date = time();
$time = "$date"+"30";
mysql_query("DELETE FROM table_name WHERE time>'$time'");
try it i hope it work 😛
If there is no user in chatroom then why do you care if chat post is there or not? It will not even make nay sense. As soon as someone enter the chatroom, all old posts will be deleted so he won't even know if there were any chat posts!
Follow me @ksg91 | My Blog: http://ksg91.com | Nokia Blog: http://NokiaTips.in
$delmessage="DELETE FROM `table` WHERE `time` < " . (time() - 300) . ";";
mysql_query($delmessage);
will delete all mesages older than 300 s (=5min). If I leave the room , and nobody come , yes , the mesages will not be deleted . but when first user come , will be deleted
Best , you can set a cron job for every 15-30 -60 min or however you want .
Unamos los corazones,hoy todos somos multicolores!
^but there is no point of using cron job for it. Jerson, why will code not execute? :/
Follow me @ksg91 | My Blog: http://ksg91.com | Nokia Blog: http://NokiaTips.in
if you still want to pace it inside the chatroom i would recomend to do it like this:
$rand = rand(0,100);
if($rand>90)
{
//10% chance to run the mysql query
mysql_query("DELETE FROM `table` WHERE `time` < " . (time() - 300));
}
also take a look at this examples if you want to leave some latest messages in the chatroom: mysql - SQL query: Delete all records from the table except latest N? - Stack Overflow
Advertise your mobile site for FREE with AdTwirl