News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Most online for each board

Started by Paul123, November 29, 2015, 02:43:01 PM

Previous topic - Next topic

Paul123

Hi all,
I was trying to get to some code to show Most Online Today for each board of smf 1.1.X, but it seems to have something to deal with database.  Is there any mod or any code that has something to deal with this.  I was trying to create another table with two items (date and mostOnline), but it always give me some errors.
Any feedback would be much appreciated.
Thanks!

margarett

We need to know what you are doing with more details. How exactly are you trying to create another table and which errors are you getting?

You should look into upgrading to 2.0.x ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Paul123

Thanks for your reply.

I created a new table using phpMyAdmin.  There is a button Create Table when opening database and I started from there with new table name:  smf_mostOnline. 

Here is the error message:
Table 'dataUser_hstd1.mostOnline' doesn't exist
File: /home1/dataUser/public_html/smf/Sources/Load.php(1739) : eval()'d code
Line: 213

Note: It appears that your database may require an upgrade. Your forum's files are currently at version SMF 1.1.21, while your database is at version 1.1.6. The above error might possibly go away if you execute the latest version of upgrade.php.


I tried to put some code in the file:  MessageIndex.Template.php just for test.  The code might not be correct, but it's just a test to see if table is working.  It might be something wrong with configuring the table. 
Thank you.

Here is the code:
                $totalMembers = $context['view_num_guests'] + count($context['view_members']);
      $date = strftime('%Y-%m-%d', forum_time(false));

      
      $request = db_query("
            SELECT NCmostOnline
            FROM {$db_prefix}mostOnline
            WHERE NCdate = '$date'
            LIMIT 1", __FILE__, __LINE__);

         // The mostOnline hasn't got an entry for today?
         if (mysql_num_rows($request) == 0)
         {
            db_query("
               INSERT IGNORE INTO {$db_prefix}mostOnline
                  (NCdate, NCmostOnline)
               VALUES ('$date', $totalMembers)", __FILE__, __LINE__);
         }
         else
         {
            list ($modSettings['mostOnlineTodayNC']) = mysql_fetch_row($request);

            if ($totalMembers > $modSettings['mostOnlineTodayNC'])
               trackStats(array('NCmostOnline' => $totalMembers));

            $totalMembers = max($totalMembers, $modSettings['mostOnlineTodayNC']);
         }
         mysql_free_result($request);

margarett

Is $db_prefix declared as a global in the function where you are running that code? Because it seems not to be translating correctly...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Paul123

Quote from: margarett on November 29, 2015, 08:13:47 PM
Is $db_prefix declared as a global in the function where you are running that code? Because it seems not to be translating correctly...

Thank you so much margarett.  It just worked after I added $db_prefix as gobal variable, and the table is updated!!

Advertisement: