Hi,
I've looked for an answer everywhere before posting this question.Basically I have multiple select combo-box whcih inserts data into a mysql database, everything works fine in the insertion.
This is the html for the combo box
<select name="insurancecovers[]" size=7 multiple id="insurancecovers[]">
<option Value="No Cover" selected>No Cover</option>
<option Value="Accident" >Accident</option>
<option Value="Medical">Medical</option>
<option Value="Car">Car</option>
<option Value="Household">Household</option>
<option Value="Funeral">Funeral</option>
<option Value="Life">Life</option>
</select>
The information is saved in the table field seperated by a coma:
Accident,Medical,Car
The problem am having is in the repopulating of the combo box in the edit mode of the application, such that if somebody had selected Accident,Medical,Car then those options are the selected ones with the rest not selected but still visible i.e.
<select name="insurancecovers[]" size=7 multiple id="insurancecovers[]">
<option Value="No Cover">No Cover</option>
<option selected Value="Accident" >Accident</option>
<option selected Value="Medical">Medical</option>
<option selected Value="Car">Car</option>
<option Value="Household">Household</option>
<option Value="Funeral">Funeral</option>
<option Value="Life">Life</option>
</select>
this is the code I have written but it don't work too good since it displays multiple values without displaying the unselected values:
//code to query database
$insuranceCovers=trim($row['insurancecovers']);
$arrInsuranceCovers=explode(",",$insuranceCovers);
$sqlIns="SELECT * FROM insurance_covers";
$db->setFetchMode(DB_FETCHMODE_ASSOC);
$result = $db->query($sqlIns);
if (DB::isError($result)) {
die ("Error executing query ".$result->getMessage());
}
$i=0;
while($row = $result->fetchRow()){
$covers=$row['cover'];
foreach($arrInsuranceCovers as $value){
if($value==$covers){
echo "<option selected value=\"$value\">$value</option>";
}else{
echo "<option value=\"$covers\">$covers</option>";
}
}
}
Any help from you guys would really be nice.
Cheers