Mysql codeigniter中的查询:获取位置或
如何选择多个或在codeigniter中 对于exmaple,Mysql codeigniter中的查询:获取位置或,mysql,codeigniter,Mysql,Codeigniter,如何选择多个或在codeigniter中 对于exmaple,从bla中选择*,其中id=1或id=2或id=3? 如果我使用这个: $this->db->where('name', $name); $this->db->where('title', $title); $this->db->where('status', $status); 使用和…您可以使用中的where_方法作为同一列的多个or语句的快捷方式: $available_ids = [1,
从bla中选择*,其中id=1或id=2或id=3?
如果我使用这个:
$this->db->where('name', $name);
$this->db->where('title', $title);
$this->db->where('status', $status);
使用和…您可以使用
中的where_
方法作为同一列的多个or语句的快捷方式:
$available_ids = [1, 2, 3];
$this->db->where_in('id', $available_ids);
// WHERE id IN (1, 2, 3)
如果要检查多个列(名称为“Adam”或标题为“Grand Poobah”或状态为“Active”),则可以使用或\u where
方法:
$this->db->where('name', $name);
$this->db->or_where('title', $title);
$this->db->or_where('status', $status);
// WHERE name = 'Adam' OR title = 'Grand Poobah' OR status = 'Active'
把这一切放在一起,你会
$available_ids = [1, 2, 3];
$query = $this->db->select('*')->from('bla')->where_in('id', $available_ids)->get();
// SELECT * FROM bla WHERE id IN (1, 2, 3)
试试这个
$array = array(
'name' => $name,
'title' => $title,
'status' => $status
);
$this->db->where($array);
将所有数据添加到数组中。然后将数组传递给where子句
但是如何在第一个选项中选择表呢?可以使用
$this->db->from($table\u name)
方法;我已更新了我的答案,以便将所有内容放在一起。请在发布问题之前搜索此网站和/或参考。