$schedule_ID = $row_schedule_ID['LAST_INSERT_ID()'];
//echo $schedule_ID;
//START A LOOP AND INSERT PEOPLE INTO THE SCHEDULE....IN ORDER OF SENORITY.
$sql_employee = 'SELECT * 
FROM `' . $db . '`.`employee` e, `' . $db . '`.`employee_shift_preference` esp 
WHERE e.`ID` = esp.`ID_employee` AND  esp.`available` = 1';
//echo $sql_employee;//debugging
$result_employee = $link->query($sql_employee);
//echo $result_employee;
while ($employee = $result_employee->fetch_assoc()) {
    //CHECK TO SEE IF SCHEUDLE IS FULL.  IF FULL THEN SCHEDULE IS DONE.
    //By looking at the how many positions are needed for the schedule and comparing that with how many have been scheduled, we can figure out whether or not the schedule is full.
    //$num_positions_needed SQL QUERY
    //By looking at the how many positions are needed for the schedule($num_positions_needed) and comparing that with how many have been scheduled($num_saved_positions_scheduled),
    //we can figure out whether or not the schedule is full.  In the event that it is, we break out of the loop.
    if (isScheduleFull($link, $db, $schedule_ID, $schedule_template)) {
        //
        break;
        //Terminate the while loop.  Schedule composition is completed.
    } else {
        //ELSE...put the person onto the schedule.
        //RETRIEVE A PERSONS INFORMATION
        $emp_id = $employee['ID'];
        $emp_senority = $employee['senority'];
        $emp_first_name = $employee['first_name'];
        $emp_last_name = $employee['last_name'];
        $emp_shift = $employee['shift'];
        $emp_non_rotational = $employee['non_rotational'];
        $emp_posted_position = $employee['posted_position'];
        //convert shift_preference(text) -> (bool) Day = 0 | Night = 1;
        $emp_shift_num;
$schedule_ID = $row_schedule_ID['LAST_INSERT_ID()'];
//echo $schedule_ID;
//START A LOOP AND INSERT PEOPLE INTO THE SCHEDULE....IN ORDER OF SENORITY.
$sql_employee = 'SELECT * 
FROM `' . $db . '`.`employee` e, `' . $db . '`.`employee_shift_preference` esp 
WHERE e.`ID` = esp.`ID_employee` AND  esp.`available` = 1 ORDER BY e.senority';
//echo $sql_employee;//debugging
$result_employee = $link->query($sql_employee);
while ($employee = $result_employee->fetch_assoc()) {
    //CHECK TO SEE IF SCHEUDLE IS FULL.  IF FULL THEN SCHEDULE IS DONE.
    //By looking at the how many positions are needed for the schedule and comparing that with how many have been scheduled, we can figure out whether or not the schedule is full.
    //$num_positions_needed SQL QUERY
    //By looking at the how many positions are needed for the schedule($num_positions_needed) and comparing that with how many have been scheduled($num_saved_positions_scheduled),
    //we can figure out whether or not the schedule is full.  In the event that it is, we break out of the loop.
    //echo isScheduleFull($link, $db, $schedule_ID, $schedule_ID);
    if (isScheduleFull($link, $db, $schedule_ID, $temp_template_id)) {
        //
        break;
        //Terminate the while loop.  Schedule composition is completed.
    } else {
        //ELSE...put the person onto the schedule.
        //RETRIEVE A PERSONS INFORMATION
        $emp_id = $employee['ID'];
        $emp_senority = $employee['senority'];
        $emp_first_name = $employee['first_name'];
        $emp_last_name = $employee['last_name'];
        $emp_shift = $employee['shift'];
        $emp_posted_position = $employee['posted_position'];
        $emp_shift_num;
        $emp_shift_num_opposite;
        if ($emp_shift == 0) {