php - codeigniter access the result set -
i new codeigniter , have following code:
$userauthenticated = $this->membership_model->userlogin($email, $pass);
and in model, following method:
function userlogin($email, $password) { $this->db->select('*'); $this->db->from('members'); $this->db->where('email', $email); $this->db->where('password', $password); $query = $this->db->get(); return $query->result(); }
i facing problem accessing $userauthenticated shown above. contains details of user tried login. how can access attributes?
regards,
replace this
return $query->result();
with this:
if ( $query->num_rows() == 1 ) { return $query->row(); } else { return false; }
replace this
$userauthenticated = $this->membership_model->userlogin($email, $pass);
with
// check negative condition first if( ! $data['userauthenticated'] = $this->membership_model->userlogin($email, $pass) ){ // show no results view $this->load->view( 'wedontknowyouatall', $data ); } else { // have result // , have passed userauthenticated $data // show result view $this->load->view( 'mysweetviewpage', $data ); }
in view page have access database fields like
echo $userauthenticated->email ;
Comments
Post a Comment