I'm trying to pull values from an array, and running into issues with how it is pulling information out of a query to a foreach loop. I want it to display each database entry into the dropdown list, however it will either give me the warning above or if I hardcode to the array it will only show the first index. Here is the code for the variables:
$countryCode = filter_input(INPUT_POST, 'countryCode');
$countryCodeQuery = 'SELECT * FROM countries';
$statements= $db->prepare($countryCodeQuery);
$statements->bindValue(':countryCode',$countryCode);
$statements->execute();
$countryCodes = $statements->fetch();
$statements->closeCursor();
Here is the code for the foreach loop:
<label>Country Code:</label>
<select name="countryCode">
<?php $countryCodeL = array($countryCodes['countryCode']) ?>
<option value="<?php echo $customerCountryCode;?>"><?php echo $customerCountryCode;?></option>
<?php foreach ($countryCodes as $countryCodeL) : ?>
<option value="<?php echo $countryCodeL['countryCode'];?>">
<?php echo $countryCodeL['countryCode'];?>
</option>
<?php endforeach; ?>
I know that the foreach loop is setup as ($array as $value), however I am getting stuck here. Can somebody give me some insight as to the issue at hand?