Codeigniter会话 - 从DB访问所有用户的Userdata值 [英] Codeigniter Session - Access Userdata value for all users from DB
本文介绍了Codeigniter会话 - 从DB访问所有用户的Userdata值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Codeigniter的Session类来存储数据库中的会话值。包含在 userdata
字段中的是用户的用户名和其他值。
I am using Codeigniter's Session class to store session values in the database. Contained within the userdata
field is the user's username and other values.
我想获得<$ c $每个 userdata
字段中的 lastactivity
is =
I want to get the username
from each userdata
field where the lastactivity
is >= let's say 5 minutes.
我可以想到的唯一方法是:
The only way I can think to accomplish this is:
- 对于在过去5分钟内活动的用户
- 获取返回的每一行的用户数据
- unserialise userdata
- username
- search for users active in last 5 minutes
- get the userdata for each row returned
- unserialise userdata
- extract username
但这看起来很长。是否有更清洁/更好的方法来做到这一点?
However this seems like the long way. Is there a cleaner/better way to do this?
推荐答案
尝试此代码。
$query = $this->db->select('user_data')->get('ci_sessions');
$user = array(); /* array to store the user data we fetch */
foreach ($query->result() as $row)
{
$udata = unserialize($row->user_data);
/* put data in array using username as key */
$user[$udata['user_name']] = $udata['user_role'];
}
从结果数组中,u可以获取所需的信息。
from the result array, u can fetch needed information.
这篇关于Codeigniter会话 - 从DB访问所有用户的Userdata值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文