Trying to get an option selected in a drop down based on the reference stored in a mysql database.
This is happening during producing a table already within a while loop.
I have tried the following focusing on the
<option selected='<? if ( $row2xsecid == $row1x[item_sub_sec_id]) { echo "selected"; } ?>' value="<? echo $row1x[item_sub_sec_id]; ?>"><? echo $row1x[item_sub_sec_title]; ?></option>
I cannot seem to get the option selected based on the reference stored in the mysql.
The snippet
<div class="input-group">
<span class="input-group-addon">Select Group</span>
<select id='add_item_groupid' class="form-control">
<?
$sql1x = 'SELECT * FROM items_sub_section_list ORDER BY item_sub_sec_id ASC';
$result1x = mysql_query($sql1x);
while ($row1x = mysql_fetch_array($result1x)) {
?>
<?
$sql2x = 'SELECT * FROM items_groups WHERE item_id=$itemid';
$result2x = mysql_query($sql2x);
while ($row2x = mysql_fetch_array($result2x)) { $row2xsecid = $row2x[item_sub_sec_id]; }
?>
<option selected='<? if ( $row2xsecid == $row1x[item_sub_sec_id]) { echo "selected"; } ?>' value="<? echo $row1x[item_sub_sec_id]; ?>"><? echo $row1x[item_sub_sec_title]; ?></option>
<?
}
?>
</select>
</div>
The pastebin of the full script - http://pastebin.com/NZrETate
<?in php.ini ?