Forum Moderators: coopster
My problem is that after these values have been inserted and the user needs to come back and update or change the options i would like the multiple select list to
A: show all available options from options table.
B: highlight the "selected Options" that have stored in the DB
Show this is what i'm using to get all the values into the select list
MYSQL QUERY TO GET ALL AVAILABLE OPTIONS
mysql_select_db($database_siteConn, $siteConn);
$query_rsGetfeatures = "SELECT options.optionID, options.option FROM options_group INNER JOIN options ON options_group.optionID = options.optionID WHERE options_group.option_typeID = 1 AND formOption = 1";
$rsGetfeatures = mysql_query($query_rsGetfeatures, $siteConn) or die(mysql_error());
$row_rsGetfeatures = mysql_fetch_assoc($rsGetfeatures);
$totalRows_rsGetfeatures = mysql_num_rows($rsGetfeatures);
SELECT LIST
<select name="option[]" size="15" multiple id="option[]">
<?php do { ?>
<option value="<?php echo $row_rsGetfeatures['optionID']?>"><?php echo $row_rsGetfeatures['option']?></option>
<?php
} while ($row_rsGetfeatures = mysql_fetch_assoc($rsGetfeatures));
$rows = mysql_num_rows($rsGetfeatures);
if($rows > 0) {
$row_rsGetfeatures = mysql_fetch_assoc($rsGetfeatures);
}
?>
</select>
MYSQL QUERY TO GET STORED VALUES
mysql_select_db($database_siteConn, $siteConn);
$query_rsGetStored = "SELECT options.optionID, options.option FROM options_group WHERE options_group.vehicleID = '". $_SESSION['vehicleID'] . "' AND formOption = 1";
$rsGetStored = mysql_query($query_rsGetStored, $siteConn) or die(mysql_error());
$row_rsStored = mysql_fetch_assoc($rsGetStored);
$totalRows_rsGetStored = mysql_num_rows($rsGetStored);
So basically i need to modify the select list so that it shows the stored values as "selected" or highlighted. I've tried various suggestions i've found but nothing seems to do what i need?
Thanks,
Cory
For example, something like this would do, working off what you already have there:
<select name="option[]" size="15" multiple id="option[]">
<?php do { ?>
<option value="<?php echo $row_rsGetfeatures['optionID']?>"
[b]<?php echo ([url=http://www.php.net/in-array]in_array[/url]($row_rsGetfeatures['optionID'], $on))? 'selected':''; ?>[/b]>
<?php echo $row_rsGetfeatures['option']?></option>
<?php
} while ($row_rsGetfeatures = mysql_fetch_assoc($rsGetfeatures));
$rows = mysql_num_rows($rsGetfeatures);
if($rows > 0) {
$row_rsGetfeatures = mysql_fetch_assoc($rsGetfeatures);
}
Please note that your code will break for the first iteration if you do not initialize $row_rsGetfeatures before this loop because it isn't first defined until the while() part. Also, the bold part in the code above--the code that I have added--utilizes the ternary operator. For more information please follow this link: [us2.php.net...]
good luck