我试图将这两个查询合并到Codeigniter中。因此,行要么必须有user_id of $user,例如3,要么有一个与数组$repost匹配的id。我知道怎么做or_where,但你怎么做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);
}
}发布于 2014-02-21 22:53:16
$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’连接。
这里有更多信息:in
https://stackoverflow.com/questions/21946311
复制相似问题