Codeigniter get_where在条件数组中带有“或”

时间:2019-02-20 00:05:30

标签: php mysql codeigniter

我正在尝试获取具有11或1112值的'yrlvl'值,但我无法通过以下代码行获取它:

$this->db->order_by('id', 'DESC');
        $query = $this->db->get_where('subjects', array('strand' => 'GAS', 'yrlvl' => '11'or '1112'));
        return $query->result_array();

我只能得到有人帮助的1112值。

1 个答案:

答案 0 :(得分:0)

以下是一些可能的解决方案:

解决方案1:

$this->db->select('*');
$this->db->from('subjects');
$this->db->where('strand', 'GAS');
$where = '(yrlvl = "11" or yrlvl = "1112")'; // make a OR statement by passing values here
$this->db->where($where);
$this->db->order_by('id', 'DESC');
$query = $this->db->get();
return $query->result_array();

解决方案2:

$this->db->select('*');
$this->db->from('subjects');
$this->db->where('strand', 'GAS');
$where = array('11', '1112'); // make an array of values for OR condition
$this->db->where_in('yrlvl', $where);
$this->db->order_by('id', 'DESC');
$query = $this->db->get();
return $query->result_array();