This Question has been re-worked to better explain:
I have a form, with a field called assign to. The field is a SELECT with MULTIPLE enabled. That field is being hooked by Jquery's autocomplete. The OPTIONS consist of an employee list, as the form is a "follow-up" ticket generator and a ticket can be assigned to multiple employees for follow-up.
The OPTIONS list is being generated by a PHP query from database getting all records from table EMPLOYEES, The OPTIONS list is made by a ECHO statement inside a WHILE LOOP. each option consists of this <option value='$rowx[employeeid],$rowx[employeename]' $keyx>$rowx[group] - $rowx[employeename]</option>
This form when in a BLANK state works just fine, but the same form is used and PRE-POPULATED with data when a user is trying to EDIT a follow-up ticket as opposed to creating a new one.
In order to PER-POPULATE the MULTI-SELECT: the database has a field called assignto
consisting of employee ID numbers (comma separated) that the follow-up being edited has been previously assigned to: Thus by example [assignto]="2345,234567,34657,32432" (Thats 4 different employees it has been tasked too)
The code below is whats generating the options list, the INTENT was that if $rowx['employeeid']
matches any value that was already in the assignto
row from the database then THAT OPTION would have the SELECTED attribute added to it. Thus giving me a per-populated multi-select. The Problem: When editing a follow-up where employee "234567" was assigned, the SELECTED is being added to 2 option fields. John doe - Employee #2345 & Jim Doe - Employee #234567 because PHP in_array
isn't looking for explicitly "23456", but instead is looking for <---- "23456" ---->
<select name="assignto[]" type="text" class="mselects" multiple="multiple" style="width:460px; overflow:hidden;">
<?php
$equery = "SELECT `employeeid`,`employeename`,`group` FROM `employees` WHERE `status` = 'A' ";
$result = mysqli_query($con,$equery);
$litmus = explode(",",$row['assignto']);
while ($rowx = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$keyx = array_search($rowx['employeeid'], $litmus);
if ($keyx >= 0) {$keyx = "selected";}
echo "<option value='$rowx[employeeid],$rowx[employeename]' $keyx>$rowx[group] - $rowx[employeename]</option>";
unset($keyx);
}
?>
</select>