I have a function as follows to populate a select
input.
$query1 = "SELECT id, address_line1, address_line2, city, state, country FROM addresses";
if($stmt = $connection->prepare($query1)){
$stmt->execute();
$stmt->bind_result($id, $addressLine1, $addressLine2, $city, $state, $country);
while($stmt->fetch()){
$addressOptions .= '<option value="'.$id.'">'.$addressLine1.", ".$addressLine2.", ".$city.", ".$state.", ".$country.'</option>';
}
$stmt->close();
}
This works fine except now I want to make it so it doesn't make an <option>
if it has an id, that is in one of the objects in my foreach loop.
This is what i have tried
$query1 = "SELECT id, address_line1, address_line2, city, state, country FROM addresses";
if($stmt = $connection->prepare($query1)){
$stmt->execute();
$stmt->bind_result($id, $addressLine1, $addressLine2, $city, $state, $country);
while($stmt->fetch()){
foreach($takenAddresses as $taken) {
if($id != $taken['id']) {
$addressOptions .= '<option value="'.$id.'">'.$addressLine1.", ".$addressLine2.", ".$city.", ".$state.", ".$country.'</option>';
}
}
}
$stmt->close();
}
```
The issue I am facing is that it shows the correct options, but each of them multiple times. If I switch it to `==` then it shows the options i want to NOT be there. But `!=` shows the options I want to be there but duplicated
EDIT
```
$query1 = "SELECT id, address_line1, address_line2, city, state, country FROM addresses";
if($stmt = $connection->prepare($query1)){
$stmt->execute();
$stmt->bind_result($id, $addressLine1, $addressLine2, $city, $state, $country);
while($stmt->fetch()){
if(!in_array($id, $takenAddresses)) {
$addressOptions .= '<option value="'.$id.'">'.$addressLine1.", ".$addressLine2.", ".$city.", ".$state.", ".$country.'</option>';
}
}
$stmt->close();
}
```