What do you guys do when you don't know the number of parameters that you are going to receive?
for example:
if($a==1) $filter.=" AND u.name = ?";
if($b==1) $filter.=" AND u.address = ?";
if($c==1) $filter.=" AND u.age = ?";
if($d==1) $filter.=" AND u.city = ?";
ETC...
$stmt->prepare("SELECT id
FROM users u
WHERE u.cp = ?
".$filter);
$stmt->bind_param("i", $cp);
And now? if you are receiving $a = 1
you will get an error because you are only passing 1 parameter on the bind_param
. So you don't know if you are going to receive 1, 2, 3 or 4 params and I don't want to make a lot of IF
or I must use a loop to count the number of parameters?