php - 如何在codeigniter中使用where子句连接两个表?

标签 php mysql 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);//使用和

关于php - 如何在codeigniter中使用where子句连接两个表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34676527/

相关文章:

javascript - 在 JQuery 脚本中刷新 CURTIME() 值

php - CakePHP 从类所属的表中获取数据

php - or_where 在 codeigniter 模型中不起作用

php - 连接到 Oracle : CodeIgniter vs Laravel

javascript - Codeigniter - jQuery 数据表 搜索和分页时不会保留复选框中的选中值

javascript - 如何将函数中找到的javascript变量值存储在php变量中

php - 从日期范围选择器获取开始和结束日期

mysql - MySQL 中名为 Status 的列

mysql - 从 MySQL 中的字段中选择最常见的值

php - 组列与无组列混合时出现错误