So I'm building an SQL statement dynamically for a small search form.
I have a series of IFs where I check what filters the user decided to use when searching.
If the user decided to use the Operating System filter (a dropdown box he chooses from), I want to add
$statement->execute(array(
':osFilter'=>$osFilter,
));
If the user selected a second filter, I need another element to be added to this array so that it looks like this:
$statement->execute(array(
':osFilter'=>$osFilter,
':versionFilter'=>$versionFilter,
));
I thought the way to do this is to create an array as I go to through the IFs and then just pass it in execute() but it didn't work.
That's the code I tried:
$filtersArray = array();
if (some condition) {
array_push($filtersArray, array(
':osFilter' => $osFilter,
));
}
I do the same for the rest of the IF statements and then pass the constructed array like this:
$statement->execute($filtersArray);
I get this error: "Array to string conversion..."
Any ideas, what's the proper way of doing things here?