如何使用codeigniter中的where子句连接两个表


How to join two tables with where clause in codeigniter?

我正在开发好友请求和通知系统!当用户发送好友请求时,第二个用户收到通知!当第二个用户接受它时,通知表在did_read字段中更新为1。我试过了,但它显示了包括已读在内的所有通知(did_read=1)。请告诉我代码中的问题在哪里。感谢

我的功能低于

public function manage_friend_req($loginuser){

    $this->db->select('from_user,to_user,did_read,avatar');
    $this->db->from('notifications');
    $this->db->join('users','users.username = notifications.from_user');
    $this->db->where(array('notifications.to_user'=>$loginuser));
    $this->db->where('notifications.did_read',0);
    $query = $this->db->get();        
    return $query->result();
 }  // 'did_read' field in database is an enum.
  1. $this->db->or_where('notifications.did_read',0)//已使用或
  2. $this->db->where('notifications.did_read',0)//已使用和