我有一个会议室预订系统,一个人预订会议室,并且公司员工可以在网络上看到预订。目前,如果当天有一个预订,它会正确绘制。
有几个会议室,任何一个都可以在 8:00 到 17:00 之间的任何时间预订。
如果有一个会议室预订,它看起来像这样:
但是当有另一个会议室预订时,在同一天,它看起来像这样:
我创建网格的 for 循环如下所示:
for($h = 8; $h < 17; $h++) { // hours
for($m = 0; $m < 4; $m++) { // 15 minutes
echo '<tr><td>' . $h . ':' . str_pad(($m*15),2,"0") . '</td>'; //plots the timeslot
foreach($boardrooms as $boardroom) { // array of boardrooms
foreach($boardroomBookings as $booking) { // array of boardroom bookings
if(date('H:i',strtotime($h . ':' . str_pad(($m*15),2,"0"))) >= date('H:i',strtotime($booking['BoardroomBooking']['start_time'])) &&
date('H:i',strtotime($h . ':' . str_pad(($m*15),2,"0"))) < date('H:i',strtotime($booking['BoardroomBooking']['end_time'])) &&
$boardroom['Boardroom']['name'] == $booking['Boardroom']['name']) {
echo '<td rowspan="0" style="background-color:#8cc63f; border-bottom:none">' . $this->Html->link($booking['BoardroomBooking']['name'], array('action' => 'view', $booking['BoardroomBooking']['id'])) . '</td>'; // writes the name into the timeslot
} else {
echo '<td></td>'; // writes an empty block
}
}
}
echo '</tr>'; // closes the row
}
}
我究竟做错了什么?
更新
这是淡化的数组(仅显示使用的数据);
$boardrooms = array(
(int) 0 => array(
'Boardroom' => array(
'name' => 'Big Boardroom (Pretoria)'
)
),
(int) 1 => array(
'Boardroom' => array(
'name' => 'Small Boardroom (Pretoria)'
)
),
(int) 2 => array(
'Boardroom' => array(
'name' => 'Medium Boardroom (No Screen) (Pretoria)'
)
),
(int) 3 => array(
'Boardroom' => array(
'name' => 'Big Boardroom (Floor 3) (Pretoria)'
)
),
(int) 4 => array(
'Boardroom' => array(
'name' => 'Big Boardroom (Durban)'
)
),
(int) 5 => array(
'Boardroom' => array(
'name' => 'Big Boardroom (Cape Town)'
)
)
)
$boardroomBookings = array(
(int) 0 => array(
'BoardroomBooking' => array(
'id' => '1206',
'name' => 'asdfasdf',
'boardroom_id' => '1',
'date' => '2013-05-21',
'start_time' => '08:15:00',
'end_time' => '10:00:00'
),
'Boardroom' => array(
'id' => '1',
'name' => 'Big Boardroom (Pretoria)'
)
),
(int) 1 => array(
'BoardroomBooking' => array(
'id' => '1208',
'name' => 'Test 2',
'boardroom_id' => '4',
'date' => '2013-05-21',
'start_time' => '09:00:00',
'end_time' => '12:00:00'
),
'Boardroom' => array(
'id' => '4',
'name' => 'Big Boardroom (Floor 3) (Pretoria)'
)
)
)