I am trying to get a select list with values from $staff
The bit i am struggling is selecting the staff that are already enrolled from $entry->enrolments.
If the $staff id exists in $entry->enrolments select it in the select list
$entry = Record from mysql
$staff = list of staff in an array.
$entry->enrolments = comma seperated values of enrolled staff
<select name="tutor[]" id="tutor" multiple="multiple" size="5" class="required" title="Select Staff">
<?php
$entry = get_record("staff_development", "id", $id);
$staff = get_records("user", "deleted", "0", "lastname ASC", "id,firstname,lastname,idnumber");
$sdenrolments=array($entry->enrolments);
$people = explode(",", $entry->enrolments);
foreach($staff as $tutor){
foreach($people as $person){
if($tutor->id>1)echo '<option value="'.$tutor->id.'"';
if ($person==$tutor->id) {echo 'selected="selected"';}
echo '>'.$tutor->lastname.' '.$tutor->firstname.'</option>';
}
}
?>
</select>
Any help/guidance would be greatly appreciated.
Thanks in advance
in_array is the easiest way to tell if a value is in an array 🙂 Replace your loops with this:
You might also want to rename your variable from
peopletoenrolled_staffor something a bit more clear.