I am trying to populate a table with rows from a database. However, one of the columns is a dropdown that needs to be populated with more than one value, therefore needing to use fetchAll. However, I am having trouble since I am using a foreach construct inside another foreach construct.
I'm guessing this isn't possible, or am I just doing something wrong? How can I find a workaround so that I can populate the entire table while also populating the dropdown with more than just one value, but still having it default to the value that it is in the database?
<?php
$sql = "SELECT TOP 100 *
FROM Table_OS_List
ORDER BY [CURRENT_SKU] ASC";
$drops = "SELECT [Purchasing_Group]
FROM Table_OS_List
GROUP BY [Purchasing_Group]";
$drop = $dbh->query($drops);
?>
<?php
/* Foreach loop that brings in information to populate table */
foreach ($dbh->query($sql) as $rows) {
?>
<tr class="row">
<td class="old_sku" id="old_sku"><?php echo intval ($rows['OLD_SKU'])?></td>
<td class="current_sku" id="current_sku"><?php echo intval ($rows['CURRENT_SKU'])?></td>
<td class="id" id="id" style="display: none;"><?php echo intval ($rows['ID'])?></td>
<td class="dropdown-select" id="purchgroup">
<select id="selected_group" class="selected_group" disabled>
<?php foreach($drop->fetchAll() as $dropdown) { ?>
<option class="choice" value="Purchasing Group"><?php echo $dropdown['Purchasing_Group'];?></option>
<?php } ?>
</select>
</td>
<td><input type="button" class="edit" name="edit" value="Edit"></td>
<td><input type="button" class="delete" name="delete" id="<?php echo intval ($rows['ID'])?>" value="Delete"></td>
</tr>
<?php
}
?>
NOTE This code correctly populates the entire table, however the dropdown list only has the value that is in each row and is not populated with the other value options if I need to select something different:
<?php
/* Foreach loop that brings in information to populate table */
foreach ($dbh->query($sql) as $rows) {
?>
<tr class="row">
<td class="old_sku" id="old_sku"><?php echo intval ($rows['OLD_SKU'])?></td>
<td class="current_sku" id="current_sku"><?php echo intval ($rows['CURRENT_SKU'])?></td>
<td class="id" id="id" style="display: none;"><?php echo intval ($rows['ID'])?></td>
<td class="dropdown-select" id="purchgroup">
<select id="selected_group" class="selected_group" disabled>
<option class="choice" value="Purchasing Group"><?php echo $rows['Purchasing_Group'];?></option>
</select>
</td>
<td><input type="button" class="edit" name="edit" value="Edit"></td>
<td><input type="button" class="delete" name="delete" id="<?php echo intval ($rows['ID'])?>" value="Delete"></td>
</tr>
<?php
}
?>
EDIT:
Each dropdown is automatically defaulting to Bowling Green even if that row should not be Bowling Green. Most rows are either Southeast or Michigan but regardless of what it should be, it is defaulting to Bowling Green for some reason


<option class="choice" value="<?php echo $rows['Purchasing_Group'];?>"><?php echo $rows['Purchasing_Group'];?></option>