[eluser]Unknown[/eluser]
As the title implies I'm trying to set session data from data in a users table in my database. My current method works, but It doesn't seem like it is the best solution. I was wondering if anyone had some suggestions to make the code a little more efficient.
Code:
if($query) { // If the users credentials validated
$this->db->where('username', $this->input->post('username'));
$users = $this->db->get('users')->result();
foreach($users as $user) {
$id = $user->id;
$username = $user->username;
}
$data = array(
'id' => $id,
'username' => $username,
'is_logged_in' => TRUE
);
$this->session->set_userdata($data);
redirect('ads');
}
Thanks.