|
 |
|
ใครก็ได้ครับ ช่วยคิดลอจิก การตรวจสอบ วันและเวลา ในการทำตาราง เพื่อให้แสดงผลตามที่ต้องการครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
$dayofweek = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');
$timephase = array(
'10:00-11:00',
'11:00-12:30',
'12:30-14:00',
'14:00-15:30',
'15:30-17:00',
'17:00-18:30',
'18:30-20:00',
'20:00-21:30');
$rsDays = array();
$rsTime = array();
while ($classResult = mysql_fetch_assoc($classQuery)):
array_push($rsDays, $classResult['class_day']);
array_push($rsTime, $classResult['class_time']);
endwhile;
print_r($rsDays);
print_r($rsTime);
<?php foreach ($timephase as $key => $value): ?>
<tr>
<td class="text-center"><?php echo $value; ?></td>
<?php foreach ($dayofweek as $dayweek): ?>
<td class="text-center">
<label onclick="javascript: insertSchedule('<?php echo $id; ?>', '<?php echo $dayweek; ?>', '<?php echo $key; ?>');">
<input type="checkbox" style="display: none;">
<span class="custom checkbox"></span>
<?php if ($rsTime[$key] == $key AND $rsDays[$key] == $dayweek): ?>
<?php echo "ok"; ?>
<?php endif; ?>
</label>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>

*โปรแกรมแสดงผล ok ไม่ตรงตามข้อมูลจากฐานข้อมูลครับ ใครก็ได้ช่วยคิดเงื่อนไขให้หน่อยครับ ขอบคุณครับ
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2013-05-30 11:35:30 |
By :
Necrotorture |
View :
1030 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนเก็บข้อมูลให้เช็กก่อน จนครบเงื่อนไข
Code (PHP)
while ($classResult = mysql_fetch_assoc($classQuery)):
$d = date('w', strtotime( $classResult['class_day']));
$dKey = $dayofweek[$d-1]; //จะได้ชื่อที่ต้องการ mon, tue, ...
if( $classResult['class_time'] >= '10.00' && $classResult['class_time'] <= '11.00'){
$data[0][$dKey] = 'ok';
}
if( $classResult['class_time'] >= '11.00' && $classResult['class_time'] <= '12.30'){
$data[1][$dKey] = 'ok';
}
.
.
.
.
.
endwhile;
ตอนวนลูปสร้างตาราง
Code (PHP)
<?php foreach ($dayofweek as $dayweek): ?>
if ( isset($data[$key][$dayweek]) && $data[$key][$dayweek] != '')
เอาจจะเขียนยาวไปหน่อยตอนเก็บข้อมูล ใครมีวิธีเร็วกว่านี้ก็แนะนำนะครับ ^^"
|
 |
 |
 |
 |
Date :
2013-05-30 16:47:33 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ทำได้แล้วครับ
Code (PHP)
<?php foreach ($timephase as $key => $value): // วนลูปช่วงเวลาที่ทำเป็นอาเรย์ไว้ ?>
<?php foreach ($dayofweek as $dayweek): // วนลูป วันในสัปดาห์ ที่ทำเป็นอาเรย์ไว้ ?>
<?php
$round = count($rsTime); // นับจำนวนข้อมูลในอาเรย์ ที่ได้จากฐานข้อมูล
$ok = 0;
for ($i = 0; $i < $round; $i++) : // วนลูปตามจำนวนที่นับได้
?>
<?php if ($rsTime[$i] == $key AND $rsDays[$i] == $dayweek): // ตรวจสอบเงื่อนไข ระหว่าง ช่วงเวลา กับ วัน ?>
<?php $ok++; // ถ้าเงื่อนไขเป็นจริง ให้เพื่มค่า $ok +1 ?>
<?php endif; ?>
<?php endfor; ?>
<?php if ($ok > 0): // ถ้า $ok มากกว่า 0 ?>
echo "ok"; // แสดงผล ok ในช่องที่เป็น วัน และช่วงเวลานี้
<?php else: ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>
**ตอนนี้โปรแกรมแสดงผลได้ตามต้องการแล้วครับ แต่ไม่รู้ว่าลูปเยอะไปรึป่าว ใครมีวิธีแนะนำได้นะครับ
|
 |
 |
 |
 |
Date :
2013-05-31 10:14:13 |
By :
Necrotorture |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|