Somnath Muluk Somnath Muluk - 1 year ago 58
MySQL Question

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

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

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

Answer Source

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.