I'm using PHP (without a framework) for an existing project and the client wants to use tags to store the data from a Select2 dropdown. I have the storage working fine, however the retrieval of the data is causing me a headache.
I'm using a while loop to repeat the options, but only the first "selected" result is coming back. Here is the code:
<select name="whoHarmed[]" id="whoHarmed" class="form-control select2-hidden-accessible" data-plugin="select2" multiple="multiple" data-options="{ tags: true }" tabindex="-1" aria-hidden="true" required>
<option value="0">Select...</option>
<?php
while(!$optionsAvailable->atEnd()) {
?>
<option value="<?php echo $optionsAvailable->getColumnVal("optionsValue") ;?>" <?php if (!(strcmp($optionsAvailable->getColumnVal("optionsValue"), ($rsOptionsSelected->getColumnVal("optionSelected"))))) {echo "selected=\"selected\"";} ?>><?php echo $optionsAvailable->getColumnVal("optionsValue") ;?></option>
<?php
$optionsAvailable->moveNext();
}
$optionsAvailable->moveFirst();
?>
</select>
That code will push out one selected item but then not the others as "tags".
I've had a google around and there seems to be a lost about retrieving the POST data (which I've dealt with) but nothing I can find about retriving the stored results from the database and then splitting them into "selected" tags.
Any pointers would be helpful.
Comments
Post a Comment