where i want to fetch only featured product. I have defined a column in database product_type in which four types of products(hot deals, newly listed, deals of the day and featured product)strong text can be listed which is optional.
Blockquote
Here is my model|query code in codeigniter public function featured_product() { $arrResult = array(); $this->db->select('*'); $this->db->from('product'); $this->db->where("product_type","featured"); $result = $this->db->get()->result_array(); if(!empty($result)) { $arrResult['result'] = $result; } else { $arrResult['result'] = ''; } return $arrResult ; }
When i try to fetch whole product list in api i get the result but i want to show only featured product.
Advertisement
Answer
As I have changed my database to separate table with product_id matching with product_type. Still I find the solution to my question with a function FIND_IN_SET()
.
Here is my updated modal query:
public function featured_product() { $arrResponse = array(); $data = 'featured'; $this->db->select('*'); $this->db->where('find_in_set("'.$data.'", product_type) <> 0'); $this->db->from('product'); $result = $this->db->get()->result_array(); if(!empty($result)) { $arrResponse['result'] = $result; } else { $arrResponse['result'] = ''; } return $arrResponse ; }