foreach($_POST["date1"] as $key=>$val){
$stime = $_POST["hour1"][$key].':'. $_POST["min1"][$key];
$etime = $_POST["hour2"][$key].':'. $_POST["min2"][$key];
$room=$_POST['txtroom'];
$strSQL = "SELECT * FROM booking WHERE r_id = '".$room."'
AND
(
(sdate='".$val."') OR ('".$val."'=edate)
)
AND
(
('".$stime."' BETWEEN stime AND etime) OR ('".$etime."' BETWEEN stime AND etime )
OR (stime between '".$stime."' and '".$etime."') OR (etime between '".$stime."' and '".$etime."')
)";
$objQuery = mysql_query($strSQL) or die(mysql_error());
$objResult = mysql_fetch_array($objQuery);
echo $strSQL."<br>";
}
if(!empty($objResult['sdate']))
{
echo "<script>alert('ห้องนี้มีผู้ใช้งานแล้วกรุณาตรวจสอบอีกครั้ง!');history.back();</script>";
}
elseif($stime > $etime){
echo "<script>alert('เวลาเริ่มต้นน้อยกว่าเวลาสิ้นสุด!');history.back();</script>";
}
$check_date = '';
foreach($_POST["date1"] as $key=>$val){
$stime = $_POST["hour1"][$key].':'. $_POST["min1"][$key];
$etime = $_POST["hour2"][$key].':'. $_POST["min2"][$key];
$room=$_POST['txtroom'];
$strSQL = "SELECT * FROM booking WHERE r_id = '".$room."'
AND ((sdate='".$val."') OR (edate='".$val."')) AND (('".$stime."' BETWEEN stime AND etime) OR ('".$etime."' BETWEEN stime AND etime )OR (stime between '".$stime."' and '".$etime."') OR (etime between '".$stime."' and '".$etime."'))";
$objQuery = mysql_query($strSQL) or die(mysql_error());
$objResult = mysql_fetch_array($objQuery);
echo $strSQL."<br>";
if(!$objResult['sdate']){
$check_date .= $objResult['sdate']. ' เวลา '. $stime .' - '. $etime;
}
}
if($check_date != '')
{
echo "<script>alert('ห้องนี้มีผู้ใช้งานแล้วกรุณาตรวจสอบอีกครั้ง! \n วันและเวลาที่จองแล้ว \n $check_date');history.back();</script>";
}
Code (SQL)
echo ออกมาได้แบบนี้อะครับ
SELECT * FROM booking WHERE r_id = '101' AND ((sdate='2013-05-31') OR ('2013-05-31'=edate)) AND (('08:00' BETWEEN stime AND etime) OR ('15:00' BETWEEN stime AND etime )OR (stime between '08:00' and '15:00') OR (etime between '08:00' and '15:00'))
2013-05-31 เวลา 08:00 - 15:00
SELECT * FROM booking WHERE r_id = '101' AND ((sdate='2013-06-04') OR ('2013-06-04'=edate)) AND (('09:00' BETWEEN stime AND etime) OR ('13:00' BETWEEN stime AND etime )OR (stime between '09:00' and '13:00') OR (etime between '09:00' and '13:00'))