![]() |
Help session grab user_id from database - 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: Help session grab user_id from database (/showthread.php?tid=51925) |
Help session grab user_id from database - El Forum - 05-23-2012 [eluser]the_unforgiven[/eluser] Hi all, I'm having major problems getting the data from from userdata even thought when i print_r the array i get this which clearly states the id is set: Code: Array ( [session_id] => f29e9f7a9facc6b8742e56a01446295d [ip_address] => 0.0.0.0 [user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:12.0) Gecko/20100101 Firefox/12.0 [last_activity] => 1337785533 [user_data] => [username] => test [is_user] => 1 [last_login] => 1337783842 [customer_id] => Array ( [id] => 14 [acc_number] => 172102 [ip_address] => 0 Basically i want to grab the id when each user is logged in and each user will have a different id obviously, but need to grab it from the session then store in a variable to use then within my controller: like so: Code: $data['cust_id'] = $this->session->userdata('id'); to pass to view or do whatever with Also i this model Code: function getCustomer() Help session grab user_id from database - El Forum - 05-23-2012 [eluser]Samus[/eluser] [quote author="the_unforgiven" date="1337786168"]Hi all, I'm having major problems getting the data from from userdata even thought when i print_r the array i get this which clearly states the id is set: Code: Array ( [session_id] => f29e9f7a9facc6b8742e56a01446295d [ip_address] => 0.0.0.0 [user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:12.0) Gecko/20100101 Firefox/12.0 [last_activity] => 1337785533 [user_data] => [username] => test [is_user] => 1 [last_login] => 1337783842 [customer_id] => Array ( [id] => 14 [acc_number] => 172102 [ip_address] => 0 Basically i want to grab the id when each user is logged in and each user will have a different id obviously, but need to grab it from the session then store in a variable to use then within my controller: like so: Code: $data['cust_id'] = $this->session->userdata('id'); to pass to view or do whatever with Also i this model Code: function getCustomer() That would work, only thing is you have 'id' nested within an array ([customer_id]). I'm not sure if this will work as it's off the top of my head, but you will either need to foreach it or access the array indexes directly. I don't know what i'm saying, but it'll look something along the lines of.. Code: $data['cust_id'] = $this->session->userdata('customer_id'); Help session grab user_id from database - El Forum - 05-23-2012 [eluser]the_unforgiven[/eluser] Unfortunatly that doesn't work Im afraid, to give you adds up on what am building might give you a better picture: Building a small e-commerce which will allow customers to register and login so i need it grab the id then i can use that id to allow each unique customer to update their details so on and so forth. Help session grab user_id from database - El Forum - 05-23-2012 [eluser]Samus[/eluser] [quote author="the_unforgiven" date="1337787646"]Unfortunatly that doesn't work Im afraid, to give you adds up on what am building might give you a better picture: Building a small e-commerce which will allow customers to register and login so i need it grab the id then i can use that id to allow each unique customer to update their details so on and so forth.[/quote] Then the problem is how you're storing the session data. Your id is being stored in a nested array, I don't see any reason it shouldn't just be stored naturally in the user_data array? Wanna post some relevant code? Help session grab user_id from database - El Forum - 05-23-2012 [eluser]the_unforgiven[/eluser] Controller to check login then store some session data: Code: function check() Model to getCustomer() Code: function getCustomer() Help session grab user_id from database - El Forum - 05-23-2012 [eluser]Samus[/eluser] Code: if($query) { model Code: function getCustomer() Let me know how that works Help session grab user_id from database - El Forum - 05-23-2012 [eluser]LuckyFella73[/eluser] Ahh never mind, I mixed some posts ... Help session grab user_id from database - El Forum - 05-23-2012 [eluser]the_unforgiven[/eluser] //'cust_id' => $this->session->userdata('id') What's happening here? :S ); was just playing whilst waiting for you to reply ealier ![]() Got this is my view file to see if worked $data['cust_id'] = $this->session->userdata('customer_id'); and just says array nothing else. Help session grab user_id from database - El Forum - 05-23-2012 [eluser]Samus[/eluser] [quote author="the_unforgiven" date="1337788708"] //'cust_id' => $this->session->userdata('id') What's happening here? :S ); was just playing whilst waiting for you to reply ealier ![]() Got this is my view file to see if worked $data['cust_id'] = $this->session->userdata('customer_id'); and just says array nothing else. [/quote] try print_r($cust_id) in your view. Help session grab user_id from database - El Forum - 05-23-2012 [eluser]the_unforgiven[/eluser] from print_r in view i get this Code: Array ( [id] => 14 [acc_number] => 172102 [ip_address] => 0 [name] => Test so the id is there right? |