$this->db->select('customer.*, feedback.*,feedback.id as fid');
$this->db->join('customer', 'customer.feedbackID = feedback.id', 'left outer');
$this->db->where('feedback.retail_id', $this->session->userdata('store_id'));
$this->db->where('feedback.fb_date BETWEEN "' . date('Y-m-d', strtotime($this->input->post('fromdate'))) . '" AND "' . date('Y-m-d', strtotime($this->input->post('todate'))) . '"');
$extra_where = explode(' ', $post_parameter);
foreach ($extra_where as $value) {`
`$this->db->or_like('feedback.comments', $value);`
}
$this->db->like('feedback.comments', $this->session->userdata('search_text'));
$data['data'] = $this->db->get('feedback')->result();
我的问题,我正在使用OR
,AND
,与运营商一样,数据无法正常获取。
MySQL查询:
SELECT `customer`.*, `feedback`.*, `feedback`.`id` as fid
FROM (`feedback`)
LEFT OUTER JOIN `customer` ON `customer`.`feedbackID` = `feedback`.`id`
WHERE `feedback`.`retail_id` = '1'
AND `feedback`.`fb_date` BETWEEN "2015-08-01" and "2015-08-31"
AND `feedback`.`comments` LIKE '%Stock%'
OR `feedback`.`comments` LIKE '%not%'
OR `feedback`.`comments` LIKE '%Found%'
示例:获取数据为aug,然后数据应该匹配,Stock找不到密钥,仅限于8月,但是也显示6月的数据,因为“not
”关键字存在于那一行。
在我必须使用的时候,我对OR
和AND
感到困惑。
答案 0 :(得分:0)
试试这个
$query = $this->db->query(
"SELECT customer.*,feedback.*,feedback.idas fid
FROM feedback AS feedback
LEFT OUTER JOIN customerONcustomer.feedbackID=feedback.id
WHERE feedback.retail_id= '1'
AND feedback.fb_date BETWEEN '2015-08-01' AND '2015-08-31'
AND feedback.commentsLIKE '%Stock%'
OR feedback.commentsLIKE '%not%'
OR feedback.commentsLIKE '%Found%'");
$result = $query->result_array();
return $result;
答案 1 :(得分:0)
使用以下代码。希望它会对你有所帮助。
$this->db->select('customer.*, feedback.*,feedback.id as fid');
$this->db->join('customer', 'customer.feedbackID = feedback.id', 'left outer');
$this->db->where('feedback.retail_id', $this->session->userdata('store_id'));
$this->db->where('feedback.fb_date BETWEEN "' . date('Y-m-d', strtotime($this->input->post('fromdate'))) . '" AND "' . date('Y-m-d', strtotime($this->input->post('todate'))) . '"');
$this->db->group_start();
$this->db->like('feedback.comments',$this->session->userdata('search_text'));
$extra_where = explode(' ', $post_parameter);
foreach ($extra_where as $value) {`
`$this->db->or_like('feedback.comments', $value);`
}
$this->db->group_end()
$data['data'] = $this->db->get('feedback')->result();