Question

One of my sites frequently has more than 1000 concurrent visitors and just for consistency I want to add a thousands separator to the display so it shows like 1,000.

My initial thought was just to add number_format before the variable holding the guest count but this stops the counter working for some reason.

The function in helper.php counting the guests looks like this:

    // show online count
static function getOnlineCount() {
    $db     = JFactory::getDbo();
    // calculate number of guests and users
    $result = array();
    $user_array  = 0;
    $guest_array = 0;
    $query  = $db->getQuery(true);
    $query->select('guest, usertype, client_id');
    $query->from('#__session');
    $query->where('client_id = 0');
    $db->setQuery($query);
    $sessions = (array) $db->loadObjectList();

    if (count($sessions)) {
        foreach ($sessions as $session) {
            // if guest increase guest count by 1
            if ($session->guest == 1 && !$session->usertype) {
                $guest_array ++;
            }
            // if member increase member count by 1
            if ($session->guest == 0) {
                $user_array ++;
            }
        }
    }

    $result['user']  = $user_array;
    $result['guest'] = $guest_array;

    return $result;
}

And in the template the data is displayed using the following:

<?php if ($showmode == 0 || $showmode == 2) : ?>
<?php $guest = JText::plural('MOD_WHOSONLINE_GUESTS', $count['guest']); ?>
<?php $member = JText::plural('MOD_WHOSONLINE_MEMBERS', $count['user']); ?>
<p><?php echo JText::sprintf('MOD_WHOSONLINE_WE_HAVE', $guest, $member); ?></p>

Where do I put the number_format so the separator is added please?

Was it helpful?

Solution

does this not work?

$guest = JText::plural('MOD_WHOSONLINE_GUESTS',number_format($count['guest'],0,'.',','));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top