How to use like, or_like and get_where together in Codeigniter 3 -


i'm trying search keyword in rows business_type manufacturer it's not working , it's getting rows. method in model:

public function search($keyword) {     $this->db->like('category',$keyword);     $this->db->or_like('keyword',$keyword);     $this->db->or_like('products_deals_with',$keyword);     $this->db->or_like('buisness_name',$keyword);     $params['conditions'] = array(         'business_type' => 'manufacturer'     );     $query = $this->db->get_where('business_listings', $params['conditions']);     return $query->result_array(); } 

generated query is:

select * `business_listings` `category` '%%' escape '!' or `keyword` '%%' escape '!' or `products_deals_with`like '%%' escape '!' or `buisness_name` '%%' escape '!' , `business_type` = 'manufacturer' 

i've found solution. i've use $this->db->group_start(); , $this->db->group_end();

public function search($keyword) {      $this->db->select('*');     $this->db->where("business_type = 'manufacturer'");     $this->db->group_start();     $this->db->like('category',$keyword);     $this->db->or_like('keyword',$keyword);     $this->db->or_like('products_deals_with',$keyword);     $this->db->or_like('buisness_name',$keyword);     $this->db->group_end();     $query = $this->db->get('business_listings');     // echo $this->db->last_query();     return $query->result_array();  } 

generated query:

select * `business_listings` `business_type` = 'manufacturer' , ( `category` '%%' escape '!' or `keyword` '%%' escape '!' or `products_deals_with` '%%' escape '!' or `buisness_name` '%%' escape '!' ) 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -