Welcome Guest, Not a member yet? Register   Sign In
where condition role.
#2

(This post was last modified: 01-08-2015, 02:31 AM by Jamie. Edit Reason: Added example )

PHP Code:
$array = array('fname' => $this->session->userdata['logged_in']['fname'], 'role' => 'admin');
$this->db->where($array);
// produces WHERE fname = 'Jamie' AND role = 'admin' 

or

PHP Code:
$this->db->where('fname',$this->session->userdata['logged_in']['fname']);
$this->db->where('role','admin');
// produces WHERE fname = 'Jamie' AND role = 'admin' 

Please see the documentation: CI3|CI2

Hope this is of some help.


Edit: On reflection the get_where() function may be neater to use.
PHP Code:
$query $this->db->get_where('users', array('fname' => $this->session->userdata['logged_in']['fname'], 'role' => 'admin')); 

An alternative way you could implement this is as follows:

PHP Code:
$query $this->db->select('fname,role')->get_where('users', array('fname' => $this->session->userdata['logged_in']['fname']));
if(
$query->num_rows() == 1) {
    
// user account exists
    
$user $this->db->row();
    if(
$user->role == 'admin') {
        
// user is admin
    
} else {
        
// user is not an admin
    
}
} else {
    
// not logged in

Jamie Bond
Full time International Development undergraduate.
Part time website developer.
Reply


Messages In This Thread
where condition role. - by jaysondotp - 01-07-2015, 10:28 PM
RE: where condition role. - by Jamie - 01-08-2015, 01:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB