I am using jquery-select2
for multiple option select.
I have a form where user can add two options from select2
select field and it is get inserted in to mysql as comma separated value. It is working ok.
Now if user want to edit it, with following code in edit_work.php
, he is seeing each tag value twice in select option.
I have two mysql databases..... one is research_tag
and second is research_work
.
During first upload user get tag values from research_tag
and it get inserted into research_work
table.
Coding I have tried in edit_work.php
is :
<div>Tags :<br><font style="font-size:12px;">Select Tags Or Keywords For Your Research Work</font></div>
<div class="form-field-input">
<?
$tags = $workdataedit['tags']; // retrives values added by user during first upload
$tagarray = explode(',', $tags);
$tagsquery = mysql_query("select * from reseach_tags order by tags ASC");
?>
<select class="js-example-basic-multiple" multiple="multiple" name="tags[]" id="tags[]" required>
<?
while ($tagdata = mysql_fetch_array($tagsquery)){
foreach ($tagarray as $item){?>
<option value="<?=$tagdata['tags']?>" <?if ($item == $tagdata['tags']){?> selected="selected"<?}?>><?=$tagdata['tags']?></option>
<?}}?>
</select>
<script type="text/javascript">
$(".js-example-basic-multiple").select2({
maximumSelectionLength: 2
});
</script>
</div>
How to get option values Only Once in Dropdown ?
Image :