2条回答 默认 最新
- dongzun9958 2016-08-09 08:42关注
On the users table you could create a column called online
Name Type Length / Val online tinyint 1
Then when the user logins in. Update that user online column to
1
Then on the a model function
public function countOnline() { $this->db->where('online', '1'); $query = $this->db->get('users'); return $query->num_rows(); }
When the user logs out. You need to set that user online column to
0
Model
Filename: Users_model.php
<?php class Users_model extends CI_Model { public function __construct() { parent::__construct(); } public function countOnline() { $this->db->where('online', '1'); $query = $this->db->get('users'); return $query->num_rows(); } }
Controller
Filename: Dashboard.php
<?php class Dashboard extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('users_model'); } public function index() { $data['online_users'] = $this->users_model->countOnline(); $this->load->view('header'); $this->load->view('dashboard', $data); $this->load->view('footer'); } }
To see new users online total you have to reload the page each time you want to see new users online.
There are scripts out there that can reload specific div's every few min.
Hope this gives you a idea
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 ETLCloud 处理json多层级问题
- ¥15 matlab中使用gurobi时报错
- ¥15 这个主板怎么能扩出一两个sata口
- ¥15 不是,这到底错哪儿了😭
- ¥15 2020长安杯与连接网探
- ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
- ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
- ¥15 可见光定位matlab仿真
- ¥15 arduino 四自由度机械臂
- ¥15 wordpress 产品图片 GIF 没法显示