Select from a table where some or one of the word is matches from a given string

32 Views Asked by At

I'm trying to get results from one of my tables using an exploded and imploded product name using the SELECT IN statement.

$prd_exp = explode(" ", $product_bname);
$prd_in = implode(",", $prd_exp);

$getRecipies = $conn->prepare("SELECT * FROM recipes WHERE r_ind IN (?)");
$getRecipies->bind_param("s", $prd_in);
$getRecipies->execute();
$recipies__res = $getRecipies->get_result();
while($row = $recipies__res->fetch_assoc()) {
      echo "> ".$row["r_name"]; // recipe name
}

r_ind contains data like this: sugar, salt, flour, egg

(words, separated by commas)

Exploded by whitespaces and imploded by commas $prd_in is look like the following: Fresh, egg, size, L

So I'd like to display recipes where the r_ind column cointains the word egg or any other word the $prd_in string gives.

After not getting any results I'm sure my sql logic is wrong. I made a ton of search but I didn't find a solution.

0

There are 0 best solutions below