簡體   English   中英

如何在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); //使用和

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM