codeigniter中的此查询无法正常工作。 LIKE运算符无法正常运行...下面的代码

时间:2018-03-06 08:11:13

标签: sql codeigniter sql-like

这里有两个条件,$ data& $ data1是不同的。

function f_report_by_year($data, $data1){
            $this->db->join('student', 'student.student_id = pay_log.student_id', 'left');
            $this->db->where('pay_log.timedate >=', $data.'-04-01');
            $this->db->where('pay_log.timedate <=', $data1.'-03-31');
            $this->db->or_like('pay_log.activity', 'MDF', 'before');
            $this->db->or_like('pay_log.activity', 'MEF', 'before');
            $this->db->or_like('pay_log.activity', 'MDD', 'before');
            $q = $this->db->get('pay_log');
            return $q->result_array();
        }

2 个答案:

答案 0 :(得分:1)

您可以使用= =&gt;

$sql = "SELECT * FROM some_table WHERE id IN ? AND status = ? AND author = ?";
$this->db->query($sql, array(array(3, 6), 'live', 'Rick'));

答案 1 :(得分:1)

试试这个or_group_start() https://www.codeigniter.com/userguide3/database/query_builder.html#query-grouping

$this->db->group_start();
$this->db->where('pay_log.timedate >=', $data.'-04-01');
$this->db->where('pay_log.timedate <=', $data1.'-03-31');
$this->db->group_end();
$this->db->group_start();
$this->db->or_like('pay_log.activity', 'MDF', 'before');
$this->db->or_like('pay_log.activity', 'MEF', 'before');
$this->db->or_like('pay_log.activity', 'MDD', 'before');
$this->db->group_end();