php - Mysql, How do i query to get name from database on base of string as input? -
i have column name in table. have value fresh cream example.
and input string have value this product made of fresh cream , fresh made.
i have tried using regular expression splitting string on base of string like
select * products product_name regexp ('[[:<:]]this[[:>:]]|[[:<:]]product[[:>:]]|[[:<:]]made[[:>:]]|[[:<:]]of[[:>:]]|[[:<:]]fresh[[:>:]]|[[:<:]]cream[[:>:]]') but in case getting records value chicken cream. want exact match of fresh cream.
is there way use locate() function that,
select * products locate(poducts.product_name , 'this product made of fresh cream , fresh made')>0 or that
you need 'name' check if input contain 1 of those. can use "like % %" expression
list_of_name = select product_name products; input = "this product made of fresh cream , fresh made."; foreach (list_of_name name){ if (strpos(input, name) !== false){ matched_name = name; break; } expr = "%" . matched_name . "%"; product = select * products product_name expr; }
Comments
Post a Comment