คำตอบที่ได้รับเลือกจากเจ้าของกระทู้
ความคิดเห็นที่ 1
นี่ครับโค้ด
<?php
$booking=array();
$date = array();
$room = array(1,2,3,4,5);
$startDate = mysql_real_escape_string($_POST['startDate']);
$endDate = mysql_real_escape_string($_POST['endDate']);
$sql="SELECT * FROM booking WHERE date_bk>='{$statDate}' and date_bk <='{$endDate}'";
$rs = mysql_query($sql);
while($row = mysql_fetch_assoc($rs)){
$booking[$row['room_num']][] = $row['date_bk']; // $booking[1][0]='2019-06-11';
}
บรรทัด58 $objStartDate = date_create ($statDate);
บรรทัด59 $objEndDate = date_create ($endDate);
$diff = date_diff( $objStartDate,$objEndDate);
$diffDays = $diff->days;
$tb = '<table><tr><th>ห้อง/วันที่</th>';
for ($i=0;$i<=$diffDays;$i++){
บรรทัด64 $date[$i] = date_format($objstartDate,'Y-m-d');
$tb = '<th>' .$date[$i].'</th>';
date_add($objStartDate,date_interval_create_from_date_string('1days'));
}
$tb.='</tr>';
foreach($room as $r){
$tb.='<tr><td>'.$r.'</td>';
foreach($date as $d){
if(isset($booking[$r])&& in_array($d,$booking[$r])){
$tb.='<td>ไม่ว่าง</td>';
}else{
$tb.='<td><a href="bk1.php?r='.$r.'&d='.$d.'">ว่าง</a></td>';
}
}
$tb.='</tr>';
}
$tb = '</table>';
echo $tb;
?>
<?php
$booking=array();
$date = array();
$room = array(1,2,3,4,5);
$startDate = mysql_real_escape_string($_POST['startDate']);
$endDate = mysql_real_escape_string($_POST['endDate']);
$sql="SELECT * FROM booking WHERE date_bk>='{$statDate}' and date_bk <='{$endDate}'";
$rs = mysql_query($sql);
while($row = mysql_fetch_assoc($rs)){
$booking[$row['room_num']][] = $row['date_bk']; // $booking[1][0]='2019-06-11';
}
บรรทัด58 $objStartDate = date_create ($statDate);
บรรทัด59 $objEndDate = date_create ($endDate);
$diff = date_diff( $objStartDate,$objEndDate);
$diffDays = $diff->days;
$tb = '<table><tr><th>ห้อง/วันที่</th>';
for ($i=0;$i<=$diffDays;$i++){
บรรทัด64 $date[$i] = date_format($objstartDate,'Y-m-d');
$tb = '<th>' .$date[$i].'</th>';
date_add($objStartDate,date_interval_create_from_date_string('1days'));
}
$tb.='</tr>';
foreach($room as $r){
$tb.='<tr><td>'.$r.'</td>';
foreach($date as $d){
if(isset($booking[$r])&& in_array($d,$booking[$r])){
$tb.='<td>ไม่ว่าง</td>';
}else{
$tb.='<td><a href="bk1.php?r='.$r.'&d='.$d.'">ว่าง</a></td>';
}
}
$tb.='</tr>';
}
$tb = '</table>';
echo $tb;
?>
แสดงความคิดเห็น
มีปัญหาTime.Zone ครับต้องไปแก้ไขตรงไหนครับ รันแล้วมันขึ้นแบบนี้
Warning: date_create(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in D:\AppServ\www\napartment\WebRps\page\bkshow.php on line 59
Warning: date_format() expects parameter 1 to be DateTimeInterface, null given in D:\AppServ\www\napartment\WebRps\page\bkshow.php on line 64