0

I'm trying to create a filter system that allows users to block out stories containing certain tags. I've sorta hit a roadblock when trying to figure out how to pass what is essentially an unknowable number of parameters.

This is my latest attempt, with no luck.

$filters = array("%#nsfw#%", "%#gore#%");
$sCount = "ss";

$query = $conn->prepare("SELECT * FROM tales WHERE tags NOT LIKE ? and tags NOT LIKE ?");
$query->bind_param($sCount, $filters);
$query->execute();
$rows = $query->get_result()->fetch_all(MYSQLI_ASSOC);
$query->close();

Is there any way at all to make this work; where "nsfw" and "gore" (and any other filters) could be passed as separate parameters?

  • Although you're using MySQLi rather than PDO, the answers in the linked duplicate still show the general approach: build a variable number of placeholders. – IMSoP Sep 27 '22 at 15:37
  • @IMSoP It's not really the variable number of placeholders I'm having trouble with, it's the variable number of inputs. Though, I will check out the link, in case it has an answer to that as well. – Albert Turing Sep 27 '22 at 19:39
  • I figured it out. Changing $query->bind_param($sCount, $filters); to $query->bind_param($sCount, ...$filters); worked for me. – Albert Turing Sep 27 '22 at 20:40

0 Answers0