I have a foreach loop that I would like to execute a prepare statement pdo. I have read a few posts on making a reference but I do not know how to do it with my code:
$str = ":City, Aurora; :State, CO";
$wherestr = explode(";",$str);
$sql = "SELECT * FROM Organization WHERE City = :City AND State= :State";
$stmt = $db->prepare($sql);
foreach ($wherestr as $ws) {
$ws = explode(",",$ws);
$ws0 = trim($ws[0]);
$ws1 = trim($ws[1]);
$stmt->bindParam($ws0,$ws1);
}
$stmt->execute();
I have read here Binding params for PDO statement inside a loop that you can make this work by creating a reference with the & symbol but I am not using a Key=>Value like they are. Can anyone help me get this to loop through the Param and execute?
If i only have one WHERE (:var) then it works fine but if i have multiple WHERE filters than it seems to override the previous filter instead of executing all of the bindParams in the execute statement. I don't get any errors it just doesn't filter the results properly with more than one var.
Thank you.