检查db的字段名称是否存在字符串[关闭]

is this possible to get the product names from database occur into string like below example:-

SELECT product_name FROM table_name WHERE product_name IN ('hello Cannabicare hi Dread Rock Coffeeshop whatsup');

in the above example Cannabicare and Dread Rock Coffeeshop are product name and can repeat multiple time becouse string generate dynamically on user post

in php i formed above query like

$search_product_name='hello Cannabicare hi Dread Rock Coffeeshop whatsup'; $query="SELECT product_name FROM table_name WHERE product_name IN ('".$search_product_name."')";

string can contain ('|,|@|#|,| etc..).

Try this. Just I have given key concept.

step1: explode your sentence(input)

step2: execute sql command depends on your splited array value

step3: push all the possible product name into your resultant array

For example:

$var = "your dynamic value";
$res = explode(" ",$var);
$prod_name = new array();
for($i=0;$i<count($res);$i++){
    $word = $res[$i];
    $prod_name = mysql_query("SELECT product_name FROM table_name WHERE product_name  LIKE '%".$word."%'");
    $productname = mysql_fetch_array($prod_name);
    array_push($prod_name,$productname);
}
print_r($prod_name);/* this is for just testing */

You have to give each product name as comma separated value. for example, if you want to search from products Cannabicare, Dread Rock Coffeeshop then you have to do like below

SELECT product_name FROM table_name WHERE product_name 
IN ('Cannabicare', 'Dread Rock Coffeeshop')