[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()
{
$data = array();
$options = array('id' => 14);
$Q = $this->db->get_where('users',$options,1);
if ($Q->num_rows() > 0){
$data = $Q->row_array();
}
$Q->free_result();
return $data;
}
i just want to get the id associted with the username thats been logged in , how does one achive such thing?[/quote]
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');
// Then to get the id, do
$data['cust_id']['id'] // which should return '14'.