Chatter of the day

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

    Chatter of the day

    Hey guys, I am working on a chatter of the day code so i have created a new database table which inserts 1 point for every chat message sent, it comprises of the uid, timesent, and the credit rows. I've managed to show how many points the top 20 members earn in total, but it doesn't restart like after 24 hours I would like for all the points disappear after 24 hours and restart, or atleast to show the top 20 members within 24 hours only, but it remains the same and keep adding up this is my code can anyone assist please?

    else if($action=="mdde")

    {

    addonline(getuid_sid($sid),"Viewing chatter of the day","");

    echo head("Chatter of day","", getuid_sid($sid));

    echo "<p align="center">";

    echo "Top 10 Members for the day";

    echo "</p>";



    //////ALL LISTS SCRIPT <<

    $oneday = time() - (24*60*60);

    //changable sql



    $sql = "SELECT COUNT(credit), uid FROM ibwf_updateday WHERE timesent>'".mysql_real_escape_string($oneday)."' GROUP BY uid ORDER BY COUNT(credit) DESC LIMIT 20";



    $items = mysql_query($sql);



    if(mysql_num_rows($items)>0)

    {

    while ($item = mysql_fetch_array($items))

    {



    $unick = getnick_uid($item[1]);

    echo "<div align="left">";

    $lnk = "&#187;<a href="index.php?action=viewuser&amp;who=$item[1]&amp;sid=$sid">".htmlspecialchars($unick)."</a> credits: $item[0]";

    echo "$lnk<br/>";

    echo "</div>";

    }

    } else {

    echo "No member of the day right now";

    }

    echo "</p>";

    ////// UNTILL HERE >>

    exit();

    }
    Last edited by tupac; 17.01.18, 22:49.

    #2
    Chat code is required to help fix
    Its probably not inserting the time into the row "timesent" (in chat.php) and then reverting back to default (0) .... So then every time is greater than 0 when called in lists.php

    Comment


      #3
      It is inserting the time bro, however, it varies lets say you post 22 messages at this exact time and then 2 more next hour, after 24 hours it only removes two and leaves the other 2 until an hour after so it's not standard it works with the time the message was posted and counts 24 hours after each one

      Comment


        #4

        I think this is what you are looking for:
        Code:
        $oneday = strtotime("-1day midnight");

        Comment


          #5
          Thanks bro good idea. I'm now trying to send a message to the top 3 members with the most points but some hun it wasn't working i was thinking something like
          if(time()>$oneday){
          }
          That would be the start i wanted to put it in core, but how do i get to pull from the table with the points and only limit it to go to the top 3 members that's my only problem bro..

          Comment


            #6
            something on the lines of:

            Code:
            $timestamp = mysql_fetch_array(mysql_query("SELECT MIN(timesent) FROM ibwf_updateday"));
            $dbDate = date('d', $timestamp[0]);
            if($dbDate!=date('d'))
            {
                $sql = "SELECT COUNT(credit), uid FROM ibwf_updateday GROUP BY uid ORDER BY COUNT(credit) DESC LIMIT 3";
                $items = mysql_query($sql);
                $i = 0;
                if(mysql_num_rows($items)>0)
                {
                    while ($item = mysql_fetch_array($items))
                    {
                        if($i==0) $msg = "congratulations first";
                        if($i==1) $msg = "congratulations second";
                        if($i==2) $msg = "congratulations third";
                         mysql_query("INSERT INTO ibwf_private SET text='".$msg."', byuid='1', touid='".$item[1]."', timesent='".time()."'");
                        $i++;
                    }
                }
            
                //Delete database contents to make sure above code is not called again
                mysql_query("DELETE FROM ibwf_updateday");
            }
            Last edited by something else; 16.01.18, 19:07.

            Comment


              #7
              Good idea bro this should work with a few modifications...well done as always bro you really are one of the best here and i know you worked hard to get where you are today...thanks again. When deleting database content i was thinking about setting it to 2 mins after then delete for example
              $tm = time();
              $dayago = mktime(0, 0, 0, date("m"), date("d"), date("y"));
              $workout = $dayago-$tm+120;
              mysql_query("DELETE FROM ibwf_updateday WHERE timesent<'".$workout."'");

              Will that work as in to prevent it from resending within that time or do you think it is a bad idea?
              Last edited by tupac; 16.01.18, 19:45.

              Comment


                #8
                Yeah that would work,

                Ideally you could do with using a cron job to run this php script.

                Otherwise you will be relying on someone being on site to run it.

                Comment


                  #9
                  Hey bro, this part
                  if($dbDate!=date('d')) { is not working as it should, it sends messages to the 10 3 members everytime they post and the delete query at the bottom which is mysql_query("DELETE FROM ibwf_updateday"); Deletes all messages and one cycle continues over and over rather than sending the message at the end of the day according to server time and then deletes the data from the table to start over....I don't really wanna use cron job for this because I don't understand it that well, but is there a quick fix for this? I've tried $mytime = mysql_fetch_array(mysql_query("SELECT MIN(timesent) FROM ibwf_updateday")); $dbdate = mktime(0, 0, 0, date("m"), date("d"), date("y")); if($mytime[0]<$dbdate) {

                  Comment


                    #10
                    Is this line correct?
                    PHP Code:
                    mysql_query("INSERT INTO ibwf_private SET text='".$msg."', byuid='1', touid='".$item[1]."', timesent='".time()."'"); 
                    I haven't got an original copy of the sql

                    Comment


                      #11
                      cron jobs are not hard to use if you have them available on your server: https://www.youtube.com/watch?v=l5Wa8sgbo2Y

                      Comment


                        #12
                        Yes bro, everything else I've altered and it's perfect. The only problem is the time message to show when to send the message at what time of the day that's the only problem lol

                        Comment


                          #13
                          Maybe instead of saving a timestamp into the database it would work better just saving the day date('d')
                          Then deleting the code etc becomes a lot easier job eg:

                          mysql_query("DELETE FROM ibwf_updateday WHERE timesent!='".date('d')."'");

                          Comment


                            #14
                            Everything works well it sends the messages to the corresponding members then it deletes all data in the table after, but the only problem is that it doesn't send the message the right time it sends it like currently, then if you post now it sends it again and deletes again and one cycle.
                            mysql_query("DELETE FROM ibwf_updateday WHERE timesent!='".date('d')."'");
                            I think that code above would probably work to delete the messages one day after, but it will keep sending it every second probably will fill the corresponding members inbox with like over a 1000 message lol
                            Last edited by tupac; 17.01.18, 18:54.

                            Comment


                              #15
                              Is the first mysql query not working?
                              PHP Code:
                              $timestamp mysql_fetch_array(mysql_query("SELECT MIN(timesent) FROM ibwf_updateday"));
                              echo 
                              "Debug: timestamp: ".$timestamp[0]." dbDay: ".date('d'$timestamp[0]). " Day: ".date('d'); 

                              Comment

                              Working...
                              X