I have a table to store the user details and it include fields such as email,mobile and password. Here my username to login can be either email or mobile number and I need to compare it with password. How can I write the query for it? I have written it like this, but it's not working
$this->db->select('*');
$this->db->from('user');
$this->db->where('email',$data['email']);
$this->db->or_where('mobile',$data['email']);
$this->db->where('password',$data['password']);
$this->db->get()->row();
I need code to compare username as either email or mobile with its password.
As is specified on official CodeIgniter documentation ( https://www.codeigniter.com/user_guide/database/query_builder.html#query-grouping ), you can group "where" statements. So, for achieving what you need, you should do the following:
$this->db->select('*')
->from('user')
->group_start()
->where('email',$data['email'])
->or_where('mobile',$data['email'])
->group_end()
->where('password',$data['password'])
->get();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.