I am in need of some help displaying the correct values from an array within an html table. I am writing a scheduling engine of sorts that will allow the user to schedule classes based on preferred dates/times and check the availability of educators.
The code below properly outputs a table with 8 weeks (in rows) and also displays my available educators (in columns). My dates are incremented 1 week at a time correctly, but the problem I am having is displaying the correct availability based on the Educator_Id. My view does not seem to be looping through the educators properly, as the same status is displayed for each educator. Reviewing the mysql logs, shows that the correct queries were executed (I can see that multiple id's were passed).
Here is what my table looks like. Week 4 should only show a personal day for Jane Doe.
Thanks for any help you can give.

My view:
<table>
<thead>
<tr>
<th>Week #</th>
<th>Date</th>
<th>Time</th>
<?php foreach($educators as $educator): ?>
<th><?php echo $educator->First_Name.' '.$educator->Last_Name; ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach($weeks as $key => $week):
$class_date= $class_dates[$key];
$week = $weeks[$key];
$master_schedule = $master_schedules[$key];
$educator_schedule = $educator_schedules[$key];
$educator_availability = $educator_availabilities[$key];
$week_day_id = $i + 1;
?>
<tr>
<td>Week <?php echo $week_day_id; ?></td>
<td><?php echo $class_date; ?></td>
<td><?php echo $opportunity->First_Preferred_Start_Time.' - '.$opportunity->First_Preferred_End_Time; ?></td>
<?php foreach($educators as $educator): ?>
<td>
<?php if($week->Count == 1): echo 'Class Conflict'; endif; ?>
<?php if($master_schedule->Count == 1): echo $master_schedule->Title; endif; ?>
<?php if($educator_schedule->Count == 1): echo $educator_schedule->Title; endif; ?>
<?php if($educator_availability->Count == 1): echo 'Not Scheduled'; endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php if($i ++ == 7) break; endforeach; ?>
</tbody>
</table>
My controller:
function schedule_opportunity($Opportunity_Id) {
//retrieve opportunity details
$this->data['opportunity'] = $this->ion_auth_model->get_opportunity($Opportunity_Id)->row();
$opportunity = $this->ion_auth_model->get_opportunity($Opportunity_Id)->row();
$Curricula_Id = $opportunity->Curricula_Id;
$Preferred_Start_Time = $opportunity->First_Preferred_Start_Time;
$Preferred_End_Time = $opportunity->First_Preferred_End_Time;
$Preferred_Start_Date = $opportunity->First_Preferred_Start_Date;
//find available educators
$this->data['educators'] = $this->ion_auth_model->available_educators($Curricula_Id);
$educators = $this->ion_auth_model->available_educators($Curricula_Id);
foreach($educators as $educator):
$Educator_Id = $educator->Educator_Id;
for($i=0; $i < 8; $i++):
$Date = strtotime("+$i week", strtotime($Preferred_Start_Date));
$Class_Date = date("Y-m-d", $Date);
$this->data['class_dates'][] = date("Y-m-d", $Date);
$this->data['weeks'][] = $this->ion_auth_model->week($Educator_Id, $Class_Date, $Preferred_Start_Time, $Preferred_End_Time)->row();
$this->data['master_schedules'][] = $this->ion_auth_model->master_schedule_check($Class_Date, $Preferred_Start_Time, $Preferred_End_Time)->row();
$this->data['educator_schedules'][] = $this->ion_auth_model->educator_schedule_check($Educator_Id, $Class_Date, $Preferred_Start_Time, $Preferred_End_Time)->row();
$this->data['educator_availabilities'][] = $this->ion_auth_model->educator_availability_check($Educator_Id, $Class_Date, $Preferred_Start_Time, $Preferred_End_Time)->row();
endfor;
endforeach;
$this->data['main_content'] = 'schedule_opportunity';
$this->load->view('./_blocks/template', $this->data);
}
My model:
function educator_schedule_check($Educator_Id, $Class_Date, $Preferred_Start_Time, $Preferred_End_Time) {
$Date = "('$Class_Date' BETWEEN Start_Date AND End_Date AND All_Day = 1 AND Educator_Id = '$Educator_Id' OR '$Class_Date' BETWEEN Start_Date AND End_Date AND (Start_Time BETWEEN '$Preferred_Start_Time' AND '$Preferred_End_Time' OR End_Time BETWEEN '$Preferred_Start_Time' AND '$Preferred_End_Time'))";
$this->db->select("Count(*) AS Count, Title")->from('Educators_Schedule')->where($Date)->where('Educator_Id', $Educator_Id);
return $this->db->get();
}