Codeigniter or_where_in [英] Codeigniter or_where_in
本文介绍了Codeigniter or_where_in的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Codeigniter 中组合这两个查询.因此,该行要么必须具有 $user 的 user_id,例如 3,要么必须具有与数组 $repost 匹配的 id.我知道怎么做 or_where 但你怎么做 or_where_in?
I am trying to combine these two queries in Codeigniter. So the row either has to have the user_id of $user eg 3 OR have an id matching the array $repost. I know how to do or_where but how do you do or_where_in?
谢谢
$this->db->where("user_id", "$user");
if (isset($conditions["repost"])) {
$user_favourited = $conditions["repost"];
$this->db->where("user_id", $user_favourited);
$this->db->select("post_id");
$this->db->from($this->repost_table);
$query = $this->db->get();
$id['posts'] = $query->result_array();
foreach($id['posts'] as $post) {
$repost[] = $post['post_id'];
}
if (isset($repost)) {
$this->db->where_in('id', $repost);
}
}
推荐答案
$this->db->or_where_in();
语法:
or_where_in([$key = NULL[, $values = NULL[, $escape = NULL]]])
参数:
$key (string) – The field to search
$values (array) – The values searched on
$escape (bool) – Whether to escape values and identifiers
退货:
DB_query_builder instance
返回类型:
object
生成一个 WHERE 字段 IN(‘item’, ‘item’) SQL 查询,如果合适,加入‘OR’.
Generates a WHERE field IN(‘item’, ‘item’) SQL query, joined with ‘OR’ if appropriate.
这篇关于Codeigniter or_where_in的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文