How to get _single_ userdata items from session database table - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How to get _single_ userdata items from session database table (/showthread.php?tid=49426) |
How to get _single_ userdata items from session database table - El Forum - 02-19-2012 [eluser]czesiek32[/eluser] Hello, this is my first post I have my session stored in database, and I want to take from the table some userdata of all users, for example their id's. It looks like this, there is a stanard db session table: Code: CREATE TABLE IF NOT EXISTS `ci_sessions` ( The userdata field looks like this: Code: a:4:{s:7:"user_id";s:1:"2";s:9:"user_name";s:18:"Name Surname";s:10:"user_admin";s:3:"yes";s:19:"user_lastlogin_date";s:10:"2012-02-18";} And I have a lot of users stored in database. Now i want to get an array of users id's - It is needed to show "who is online" after join with users table in DB. And here is my question - how could i get this array ? Regexp ? I don't think so. I hope there is a way to get all userdata fields but not looking like s**t (a:4:{s:7:"user_id";s:1:"2";s:9:"user_name";s:18:"Name Surname";s:10:"user_admin";s:3:"yes";s:19:"user_lastlogin_date";s:10:"2012-02-18";}) but like variables ($user_id=2, $user_name="Name Surname") and so on. I hope you can understand what i mean, thanks for any help. How to get _single_ userdata items from session database table - El Forum - 02-19-2012 [eluser]InsiteFX[/eluser] When ci stores the array in the table it serializes it! So to get the array it needs to be unserizlized. See ./system/libaries/Session.php Code: $user = $this->session->all_userdata(); How to get _single_ userdata items from session database table - El Forum - 02-19-2012 [eluser]czesiek32[/eluser] [quote author="InsiteFX" date="1329659687"]When ci stores the array in the table it serializes it! So to get the array it needs to be unserizlized. See ./system/libaries/Session.php Code: $user = $this->session->all_userdata(); Everything is clear for me now, thank you! How to get _single_ userdata items from session database table - El Forum - 02-20-2012 [eluser]czesiek32[/eluser] I have made session model like above - unserialize() is used in constructor, so i have single userdata in class variables That was my very first time with data serialization, that is why i had no idea what is that before your answer - thanks again. Code: <?php How to get _single_ userdata items from session database table - El Forum - 02-20-2012 [eluser]InsiteFX[/eluser] You do not need to do it like that, the $this->session->all_userdata() returns all the data to you already unserialized! Example: Code: $data = array(); How to get _single_ userdata items from session database table - El Forum - 02-20-2012 [eluser]czesiek32[/eluser] [quote author="InsiteFX" date="1329742971"]You do not need to do it like that, the $this->session->all_userdata() returns all the data to you already unserialized! Example: Code: $data = array(); I know that, but in this case i needed to take all (or almost all) users user_data from session table in database, not only mine data which i can retrive by Code: $this->session->all_userdata(); How to get _single_ userdata items from session database table - El Forum - 02-20-2012 [eluser]InsiteFX[/eluser] Ok, I see what your doing now! |