phpcodeignitersearch

How to add where in 3 condition


I have some model for searching like this,

public function get_products_by_keyword($keyword) {
    $this->db->select('*');
    $this->db->from('item');
    $this->db->like('item_name',$keyword);
    $this->db->where('item_product_type', 'watches');
    return $this->db->get()->result();
  }

item_product_type list: watches, building, aksesoris, eyeware, promo

in the database, I have 5 item_product_type but I want to show just 3 categories, how to do that in CodeIgniter?


Solution

  • You can use where_in to pass three type lists

    $this->db->where_in('item_product_type', ["watches", "building", "aksesoris"]);
    

    Official doc.