Delete chatpost automatically.

Started on the old forum in June 2011 · view the original in the archive · old links redirect here

9 replies · 486 views · started 15 years ago · 1 min read

5 participants
Jerson Developer · 70 posts #1

I need help. Im writing my own script.. My table structure is like this... id,chatpost,time

my problem is to delete old chatpost after 5 mins.... S0methng like this

if(time() >= $raw['time']) { then delete old chatpost. }

feel free to post... Haha thanks 🙂

atef Developer · 224 posts #2
$date = time();
$time = "$date"+"30";
mysql_query("DELETE FROM table_name WHERE time>'$time'");

try it i hope it work 😛

Jerson Developer · 70 posts #3

Yes it helps but i think the code will not execute if there is no user that will reload or open the the php file. Just something to ad like this if $timeinthedb < time() then delete... Im almost crazy in thnking how to code my logic. Haha im funckin going insane! Thanks a lot..

ksg91 Developer · 162 posts #4

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

morency Senior · 488 posts #5

..and add the code in page with room list , not in chat room . Because in chat room will be so many reloads. I delete after 15 minutes , not after 5 .

Unamos los corazones,hoy todos somos multicolores!

Jerson Developer · 70 posts #6

No u dont understand... 4 example ur the last visitor in the room then u leave. The old post will n0t expire.. Because if the users will back after the expiration time the code will n0t execute... And the post will remain.

morency Senior · 488 posts #7
 $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!

GumSlone Administrator Principal · 1,690 posts #9

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

External image (may be gone)

Jerson Developer · 70 posts #10

Thanks! You help a lot.

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close