I have had no trouble passing multiple values into a single IN statement, but when I have multiple IN statements in a single statement it is where I am struggling.
Below is how I am doing it for a single IN statement:
$sql = "SELECT *
FROM x
INNER JOIN y
ON x.id = y.d_id";
if (isset($_GET['c'])) {
$catVals = explode(',', $_GET['c']);
$catValsPlaceholder = implode(',', array_fill(0, count($catVals), '?'));
$sql .= " WHERE y.category IN ($catValsPlaceholder)";
} else {
}
$sql .= " GROUP BY y.d_id
ORDER BY x.updated ASC
LIMIT 1000";
$sth = $pdo->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
if(isset($_GET['c'])) {
$sth->execute($catVals);
}
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
But when I add another IN query I am unsure how to execute both using execute(). Some context, I pass vars from my App so c = a,b,c,d or d = value,value2,value3
if (isset($_GET['c']) && isset($_GET['d'])) {
$catVals = explode(',', $_GET['c']);
$catValsPlaceholder = implode(',', array_fill(0, count($catVals), '?'));
$typeVals= explode(',', $_GET['d']);
$typePlaceholder= implode(',', array_fill(0, count($typeVals), '?'));
$sql .= " WHERE y.category IN ($catValsPlaceholder)";
$sql .= " AND y.type IN ($typePlaceholder)";
}