where condition role. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 2.x (https://forum.codeigniter.com/forumdisplay.php?fid=18) +--- Thread: where condition role. (/showthread.php?tid=708) |
where condition role. - jaysondotp - 01-07-2015 Hi Coders, i have user table with role, ADMIN AND USER now i have a one page, that if the user login as user, he/she can view his own work while if the user login as admin he can view all user works? any body how to implement it. wrong condition.... PHP Code: $this->db->where('users.fname',$this->session->userdata['logged_in']['fname'] AND 'users.role','admin'); RE: where condition role. - Jamie - 01-08-2015 PHP Code: $array = array('fname' => $this->session->userdata['logged_in']['fname'], 'role' => 'admin'); or PHP Code: $this->db->where('fname',$this->session->userdata['logged_in']['fname']); 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'])); |