如何在codeigniter中加入列

时间:2012-12-14 14:14:52

标签: codeigniter

登录(id,name,role,user_id) 老师(teacher_id)

我需要检查角色是2.

$this->db->select('*');     
$this->db->from('teacher');     
$this->db->where('teacher_branch_id',$this->session->userdata('branch_id'));
$this->db->join('login','teacher.teacher_id = login.login_user_id');

$query = $this->db->get();

1 个答案:

答案 0 :(得分:2)

只需添加以下条件:$this->db->where('login.role', 2);

$this->db->select('*');     
$this->db->from('teacher');     
$this->db->join('login', 'teacher.teacher_id = login.login_user_id');
$this->db->where('teacher_branch_id', $this->session->userdata('branch_id'));
$this->db->where('login.role', 2);

$query = $this->db->get();