[eluser]surf66[/eluser]
Hello...
In my system, when a user logs in, their username is added into the session data.
I would also like to run a query in order to retrieve their user_id from the database and add this into the session data as well. It is a pretty straight forward query and all usernames in the db are unique so every time I should be pulling out just one id from the db, there should be no problems there.
Below is my login function where I am setting my session data. If anyone could help, all I want to do is grab the users id from db where it matches their username and set it in session data
Thank you in advance
Code:
function login(){
$username = $this->input->post('username');
//get the user id and set it in the session data
$this->db->select('user_id');
$this->db->from('student_users');
$this->db->where('user_username', $username);
$query = $this->db->get();
return $query->row_array();
$user_id = $query['user_id'];
$data = array(
'username' => $this->input->post('username'), //this works fine
'user_id' => $user_id, //this is where i want to set the user_id in session data
'logged_in' => TRUE
);
$this->session->set_userdata($data);
} //function login()