我试图从数据库中获取result_array()
,其中两列必须返回true,反之亦然,所以我决定使用or_where
,但我的代码返回Call to undefined method CI_DB_mysqli_result::or_where()
错误,任何建议怎么能实现这个?
我在CI_Model内部使用下面的代码。
public function check_request($userid, $senderid){
$query = $this->db->get_where('connection',array('user_id' => $userid, 'sender_id' => $senderid));
$query = $this->db->or_where('connection',array('sender_id' => $userid, 'user_id' => $senderid));
return $query->result_array();
}
答案 0 :(得分:1)
尝试下面的内容:
public function check_request($userid, $senderid){
$this->db->select('*');
$this->db->where("(user_id = '$userid' AND sender_id = '$senderid')
OR (sender_id='$userid' AND user_id = '$senderid')");
$query = $this->db->get('connection');
return $query->result_array();
}
答案 1 :(得分:1)
你可以这样试试。在某天之前我遇到了同样的问题。我试过这样的
$query = $this->db->select('*')
->where("(user_id = '$userid' AND sender_id = '$senderid') OR (user_id = '$senderid' AND sender_id = '$userid')")
->get('connection');
return $query->result_array();