php - CodeIgniter 3 Query ESCAPE '!' Ignoring the WHERE statement? -
i building site search select boxes categories & regions. if selected including in query, reason, using ignoring section of query!?!? why or doing wrong?
when echo query built codeigniter fololowing: (note escape '!')
query echo:
select sql_calc_found_rows null rows, ads.id id, location, provlabel, text, adcat.id catid, ads.subcatid subcatid, ads.province r_rand, r_option, addate, adcat.name catname, adsubcat.name subname, f_value, adtitle, ads.area, regionlabel, adlink `ads` join `search_town` on `search_town`.`townid`=`ads`.`townid` join `search_region` on `search_region`.`regionid`=`ads`.`area` join `search_prov` on `search_prov`.`provid`=`ads`.`province` join `adcat` on `adcat`.`id`=`ads`.`catid` join `adsubcat` on `adsubcat`.`id`=`ads`.`subcatid` left join `adfields` on `adfields`.`ad_id`=`ads`.`id` `ads`.`catid` != 8 , `ads`.`adactive` = 1 , `scam` =0 , `ads`.`province` = '1' , `ads`.`catid` = '3' , `text` '%nissan%' escape '!' or `f_value` '%nissan%' escape '!' group `ads`.`id` order `addate` desc limit 10
here actual query in controller:
public function get_search($fsearch, $fcategory, $fprovince, $farea, $limit, $start) { if($fcategory >=1){ $incl_cat=" , ads.catid='$fcategory'"; }else{ $incl_cat=''; } if($fprovince>=1){ $incl_prov=" , ads.province='$fprovince'"; }else{ $incl_prov=''; } if($farea >= 1){ $incl_area=" , ads.area='$farea'"; }else{ $incl_area=''; } $this->db->select('sql_calc_found_rows null rows, ads.id id, location, provlabel, text, adcat.id catid, ads.subcatid subcatid,ads.province r_rand, r_option, addate, adcat.name catname, adsubcat.name subname, f_value, adtitle, ads.area, regionlabel, adlink', false); $this->db->from('ads'); $this->db->join('search_town', 'search_town.townid=ads.townid'); $this->db->join('search_region', 'search_region.regionid=ads.area'); $this->db->join('search_prov', 'search_prov.provid=ads.province'); $this->db->join('adcat', 'adcat.id=ads.catid'); $this->db->join('adsubcat', 'adsubcat.id=ads.subcatid'); $this->db->join('adfields', 'adfields.ad_id=ads.id', 'left'); $where = "ads.catid!=8 , ads.adactive=1 , scam=0 $incl_prov $incl_cat $incl_area"; $this->db->where($where); $this->db->like('text', $fsearch); $this->db->or_like('f_value', $fsearch); $this->db->group_by("ads.id"); $this->db->order_by('addate', 'desc'); $this->db->limit($limit, $start); $query = $this->db->get(); $return = $query->result_array(); echo $this->db->last_query(); $total_results=$this->db->query('select found_rows() count;')->row()->count; $this->session->set_userdata('tot_search', $total_results); return $return; }
your condition
a , b , c , d , ... , x or y
if y
true whole condition true.
perhaps mean:
a , b , c , d , ... , (x or y)
the escape character defaults \
, looks codeigniter has changed !
(presumably because \
escape in php, need multiples , can confusing).
currently irrelevant query. used if need match %
or _
!%
or !_
(default \%
or \_
).
Comments
Post a Comment