Delete chatpost automatically.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Delete chatpost automatically.

    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

    #2
    PHP Code:
    $date time();
    $time "$date"+"30";
    mysql_query("DELETE FROM table_name WHERE time>'$time'"); 
    try it i hope it work :p

    Comment


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

      Comment


        #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

        Comment


          #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!

          Comment


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

            Comment


              #7
              PHP Code:
               $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!

              Comment


                #8
                ^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

                Comment


                  #9
                  if you still want to pace it inside the chatroom i would recomend to do it like this:

                  PHP Code:
                  $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

                  Comment


                    #10
                    Thanks! You help a lot.

                    Comment

                    Working...
                    X