0

I would like to search wildcard query in my php.model file.

I tried to apply these code but always get empty result.

public function get_web_search($data) {
       $sql = "select p.name,c.name AS category_name,p.product_id AS item_id ,'Product' AS category_group from  product p left join category c on p.category_id = c.category_id  WHERE p.name LIKE '%?%' UNION select m.merchant_name,c.name AS category_name,m.merchant_id AS id,'Merchant'  AS category_group  from  merchant m left join category c on m.category_id = c.category_id WHERE m.merchant_name LIKE '%?%'";
       $result = $this->db->query($sql, array($data['id'],$data['id']));
       $records = $result->result_array();
       return $records;
   }

May I know how to set proper select statement in p.name LIKE '%?%' ?

Please help. Thank you.

AD Tee
  • 345
  • 4
  • 21
  • Use `?` (not `'%?%'`) in your query, and replace `$data['id']` in your call to `query` (which I presume prepares the statement and executes it) with `'%'.$data['id'].'%'` – Nick May 24 '19 at 08:13
  • @Nick, thanks for your help. it's work like charm! – AD Tee May 24 '19 at 08:21
  • Good to hear - I always try to provide a solution when closing a question as a duplicate. – Nick May 24 '19 at 08:23
  • I stuck and overlooked similar question that asked before. Anyway, thanks for your help. – AD Tee May 24 '19 at 08:25

0 Answers0