其中条件紧随或条件在编码器中不起作用



当我只使用3个OR条件中的一个OR条件时,where子句不起作用。

$this->db->where('(delivery_date BETWEEN "'.$from.'" AND "'.$to.'") ');
$this->db->or_where('order_date BETWEEN "'.$odfrom.'" AND "'.$odto.'"');
$this->db->or_where('mumbai_date BETWEEN "'.$mdfrom.'" AND "'.$mdto.'"');
$this->db->where('order_location',$sess_location);
$this->db->where('designer_id',$sess_designer_id);
$this->db->where('is_deleted=',0);
$query= $this->db->limit($length,$start)->get();
return $query->result();

在带括号的编码点火器圆形"or_where"条件下;

$this->db->where('(delivery_date BETWEEN "'.$from.'" AND "'.$to.'") ');
$this->db->where('((order_date BETWEEN "'.$odfrom.'" AND "'.$odto
.'") OR (mumbai_date BETWEEN "'.$mdfrom.'" AND "'.$mdto.'"))',NULL,false);
$this->db->where('order_location',$sess_location);
$this->db->where('designer_id',$sess_designer_id);
$this->db->where('is_deleted=',0);
$query= $this->db->limit($length,$start)->get();

虽然这个问题已经有了答案,但我可能会补充 -

你永远不应该在你的查询中使用未转义的数据,因为你对SQL注入完全开放 - 请仔细阅读QueryBuilder文档和查询文档 - 特别是转义的部分。

可以这么说,以下代码更适合您的情况

$query = $this->db
->group_start()
->where('delivery_date >=', $from)
->where('delivery_date <=', $to)
->group_end()   
->group_start()
->group_start()
->where('order_date >=', $odfrom)
->where('order_date <=', $odto)
->group_end()
->or_group_start()
->where('mumbai_date >=', $mdfrom)
->where('mumbai_date <=', $mdto)
->group_end()
->group_end()
->where('order_location', $sess_location)
->where('designer_id',$sess_designer_id)
->where('is_deleted=',0)
->limit($length, $start)
->get();

或者,如果您真的想使用between则可以这样做

$query = $this->db
->group_start()
->where('delivery_date BETWEEN '.$this->db->escape($from).' AND '.$this->db->escape($to))
->group_end()   
->group_start()
->group_start()
->where('order_date BETWEEN '.$this->db->escape($odfrom).' AND '.$this->db->escape($odto))
->group_end()
->or_group_start()
->where('mumbai_date BETWEEN '.$this->db->escape($mdfrom).' AND '.$this->db->escape($mdto))
->group_end()
->group_end()
->where('order_location', $sess_location)
->where('designer_id',$sess_designer_id)
->where('is_deleted=',0)
->limit($length, $start)
->get();

相关内容

  • 没有找到相关文章

最新更新