Hi all,

What tables can I query to see "Most Users Ever Been Online" on my site? There is a block that says "Who's online" that displays current users online, but how to get most users ever online?

Thanks for your help!

Comments

batbug2’s picture

$output = '';
        
        // part for displainy number of online users and guests
        $interval = time() - 900; // 900 - how many seconds past for online
        $anonymous_count = sess_count($interval);
        $authenticated_users = db_query('SELECT DISTINCT u.uid, u.name, s.timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= %d AND s.uid > 0 ORDER BY s.timestamp DESC', $interval);
        $authenticated_count = db_num_rows($authenticated_users);
        if ($anonymous_count == 1 && $authenticated_count == 1)
                $output .= t('There is currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests')));
        else
                $output .= t('There are currently %members and %visitors online.', array('%members' => format_plural($authenticated_count, '1 user', '@count users'), '%visitors' => format_plural($anonymous_count, '1 guest', '@count guests')));
        $max_users = 1000;
        $output .=  '<div id="my_block_users_online">'."\n";
        if ($authenticated_count && $max_users) {
                $items = array();
                if ($max_users-- && $account = db_fetch_object($authenticated_users)) {
                        $output .= theme('username', $account);
                        while ($max_users-- && $account = db_fetch_object($authenticated_users)) {
                                $output .= ', '.theme('username', $account);
                        }
                        $output .= '.';
                }
        }
        $output .= '</div>'."\n";
 
        // online users list
        $output .= '<div id="my_block_users_new">'."\n";
        $new_user_result = db_query('SELECT uid, name, created as timestamp FROM {users} WHERE status != 0 AND access != 0 ORDER BY created DESC LIMIT 1');
        if ($new_user = db_fetch_object($new_user_result)) {
                $output .= 'Приветствуем нового пользователя: ';
                $output .= theme('username', $new_user);
        }
        $output .= '</div>'."\n";
 
        // most ever users online
        $output .= '<div id="my_block_users_maximum">'."\n";
        $umax = variable_get('user_online_max', array('count' => 0, 'date' => '0'));
        if ($umax['count'] == 0 || $umax['count'] <= ($authenticated_count + $anonymous_count)) {
                $umax['count'] = $authenticated_count + $anonymous_count;
                $umax['date'] = time();
                variable_set('user_online_max', $umax);
        }
        $output .= 'most ever users online -  <strong>'.$umax['count'].'</strong>, it was on <span class="date">'.format_date($umax['date'], 'custom', 'd.m.Y в H:i', NULL).'</span>.';
        $output .= '</div>'."\n";
 
      
        // outputting the block
        print $output;

hope that helps

CompShack’s picture

Thanks for the block - I will give it a try.

Thanks again!
-----------------------------------------
Finally, I CMS that I Like!
http://www.CompShack.com

Aniara.io’s picture

This seems to work, although you have to change line 9 from $authenticated_count = db_num_rows($authenticated_users); to the Drupal 6 version of $authenticated_count = db_result($authenticated_users); and change the Russian(?) lines at the bottom of the script. I got the following result at Babel: Приветствуем нового пользователя = "We greet the new user".