Hi there,
I'm trying to populate a multiple select field from mysql. I already have the info stored in mysql, and separated by "<br>". Now I'm calling that info back like this:
<?
$pieces = explode("<br>", $society_inf); // society_inf is the mysql field name AND the variable name, for simplicity
?>
<select name="society_inf[]" multiple="multiple" id="society_inf" tabindex="290">
<?php if($pieces[0] !== ""){echo "<option value=\"$pieces[0]\" selected>$pieces[0]</option>"; } else { echo "";}?>
<?php if($pieces[1] !== ""){echo "<option value=\"$pieces[1]\" selected>$pieces[1]</option>"; } else { echo "";}?>
<?php if($pieces[2] !== ""){echo "<option value=\"$pieces[2]\" selected>$pieces[2]</option>"; } else { echo "";}?>
<?php if($pieces[3] !== ""){echo "<option value=\"$pieces[3]\" selected>$pieces[3]</option>"; } else { echo "";}?>
<?php if($pieces[4] !== ""){echo "<option value=\"$pieces[4]\" selected>$pieces[4]</option>"; } else { echo "";}?>
<option value="AAPM – American Academy of Pain Medicine" selected>AAPM – American Academy of Pain Medicine</option>
<option value="APS – American Pain Society">APS – American Pain Society</option>
<option value="AACE – American Association of Clinical Endocrinologists">AACE – American Association of Clinical Endocrinologists</option>
<option value="ECE – European Congress of Endocrinology">ECE – European Congress of Endocrinology</option>
<option value="ENDO – The Endocrine Society">ENDO – The Endocrine Society</option>
<option value="ENEA – European Neuro Endocrine Association">ENEA – European Neuro Endocrine Association</option>
<option value="ESPE – European Society for Paediatric Endocrinology">ESPE – European Society for Paediatric Endocrinology</option>
<option value="LWPES – Lawson-Wilkins Pediatric Endocrine Society">LWPES – Lawson-Wilkins Pediatric Endocrine Society</option>
</select>
Here's what it looks like: (the two selected ARE supposed to be)
You can see this looks kind of ugly, but it's almost working for me.
My question is:
Is there a way to loop this array to where it only shows me the selected items (still selected) and the non-selected items (still NOT selected), but no duplicates?
I'd like it to look like this:
[attachment deleted by admin]