0

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.

ADyson
  • 57,178
  • 14
  • 51
  • 63
nothes
  • 1
  • 4
  • What do you think `$prd_in` will contain exactly ?? – Ken Lee Jun 17 '23 at 08:26
  • You need one ? for each separate word. It can't be all one parameter. There examples of using IN dynamically with parameters online already – ADyson Jun 17 '23 at 08:26

0 Answers0