php - Multiple joins with where, like and or_like CodeIgniter 3 Active Records -


i trying this:

        $location = 'a';         $this->db->select('l.id, d.guests, l.city, l.country');         $this->db->from('offers o');         $this->db->join('location l', 'l.id = o.id', 'left');         $this->db->join('desc d', 'd.offer_id = o.id', 'left');         $this->db->where('d.guests', $guests);         $this->db->where('o.completed', 1);         $this->db->where('l.country like', $location.'%');         $this->db->or_where('l.city like', $location.'%');         $this->db->limit(5); 

and have offer 3 guests , country albania (1 row per table it). but, if $guests = 2; have result 1 row. same, if use like , or_like instead where , or_where. if comment line:

$this->db->or_where('l.city like', $location.'%');

all works fine, have no results if $guests != 3 , 1 row result if $guests = 3.

generated query $this-db->last_query() is:

select 'l'.'id', 'd'.'guests', 'l'.'city', 'l'.'country' 'offers' 'o' left join 'location' 'l' on 'l'.'id' = 'o'.'id' left join 'desc' 'd' on 'd'.'id' = 'o'.'id' 'd'.'guests' = 3 , 'o'.'completed' = 1 , 'l'.'country' 'a%' or 'l'.'city' 'a%' limit 5

how can make query ? select values completed = 1, guests = $guests , city or country $location.

try code

$location = 'a'; $this->db->select('l.id, d.guests, l.city, l.country'); $this->db->from('offers o'); $this->db->join('location l', 'l.id = o.id', 'left'); $this->db->join('desc d', 'd.offer_id = o.id', 'left'); $this->db->where('d.guests', $guests); $this->db->where('o.completed', 1); $this->db->where("(l.country '".$location."%' or l.city '".$location."%')"); $this->db->limit(5); 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -