How to access array values in ci_session table's user_data column?

How to access values from ci_sessions table's "user_data" column in codeigniter.

Suppose I have added user_name, user_role in session. I have to display all active users name and their roles.

Answers


This is how I would do it:

$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']; 
}

You can then iterate over $user, print its contents, etc.


Need Your Help

Sorting an array of dates

asp.net arrays vb.net asp.net-4.0

I have created an array from a CSV of date values and now need to be able to sort them so that I can then get the latest date from the array.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.