Reputation: 5747
I can't seem to find the documentation laying this out clearly.
public function get_user_id_from_username($username){
$this->db->where('username', $username);
$this->db->select('id');
$query = $this->db->get('users');
}
Quite simply, I want to return the id that I have just selected from the database. Can anyway tell me how I get access to that id?
Thanks.
Upvotes: 0
Views: 51
Reputation: 2915
public function get_user_id_from_username($username){
$query='select id from users where username=?';
$params=array();
$params[]=$username;
$result=$this->db->query($query, $params);
$result=$result->row_array();
return $result['id'];
}
if you're expecting multiple rows result_array works:
$result=$this->db->query($query, $params);
$result=$result->result_array();
//uses the form $result[0]['id']
//try a print_r
print_r($result);
Upvotes: 1
Reputation: 219864
The manual was very enlightening
$row = $query->row();
echo $row->id;
Upvotes: 1