我的一个网站经常有超过1000个并发访问者,为了保持一致性,我想在显示屏上添加千位分隔符,使其显示为1,000。
我最初的想法是在保持访客数量的变量之前添加number_format,但这会因某种原因停止计数器工作。
helper.php中计算guest虚拟机的函数如下所示:
// 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;
}
在模板中,数据显示如下:
<?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>
我在哪里放入number_format以便添加分隔符?
答案 0 :(得分:0)
这不起作用吗?
$guest = JText::plural('MOD_WHOSONLINE_GUESTS',number_format($count['guest'],0,'.',','));