Hi All
I have a list form field where the list options are taken from one table and some of the options are 'selected' depending on corresponding values from a second table.
I have an array of all the sectors to list in the form and have created an array of the selected options from the user table. I need to compare these and decide whether the option is selected or not. I have code which I think is close but it doesn't work and there are no obvious errors:
<?php
$sect_list_str = $userrow['category'];
$sect_list = split(':', $sect_list_str);
?>
<td colspan="3" height="2" width="338">
<select name="sector[]" MULTIPLE size="8">
<option value="">Select industry sector...</option>
<?php
$getsectorsql = "SELECT * FROM sect ORDER BY sector_name";
$db = mysql_connect($db_host,$db_user,$db_pass);
$sectorresult = mysql_query($getsectorsql,$db);
while ($myrow=mysql_fetch_array($sectorresult)) {
if ( source_selected( $myrow['id'], $sect_list) ) {
printf("<option value=\"%s\" selected>%s</option>",$myrow['id'],$myrow['sector_name']);
} else {
printf("<option value=\"%s\">%s</option>",$myrow['id'],$myrow['sector_name']);
}
}
?>