|
|
|
code ส่วนนี้ ยังสามารถจองห้องทับซ้อนวันและเวลากันได้ ต้องแก้ไขอย่างไรบ้างคับ วอนผู้รู้ช่วยหน่อยคับ |
|
|
|
|
|
|
|
<?php
include_once("connectdb.php");
$time1 = $_POST["myHour1"] . ":" . $_POST["myMin1"] . ":00";
$time2 = $_POST["myHour2"] . ":" . $_POST["myMin2"] . ":00";
/* $strSQL = "SELECT * FROM meeting_list WHERE ((strdate between '" . $_POST["myDate1"] . "' and '" . $_POST["myDate2"] . "') or ";
$strSQL .= " (enddate between '" . $_POST["myDate1"] . "' and '" . $_POST["myDate2"] . "')) and ";
$strSQL .= " ((strtime between '" . $time1 . "' and '" . $time2 . "') or ";
$strSQL .= " (endtime between '" . $time1 . "' and '" . $time2 . "')) and room = '" . $_POST["myRoom"] . "' and mstatus in('Y','N') "; */
/* $strSQL = "SELECT count(*)as count_meeting FROM meeting_list WHERE ((concat(strdate,' ',strtime) between '" . $_POST["myDate1"] . " " . $time1 . "' and '" . $_POST["myDate2"] . " " . $time2 . "') "
. "or (concat(enddate,' ',endtime) between '" . $_POST["myDate1"] . " " . $time1 . "' and '" . $_POST["myDate2"] . " " . $time2 . "')) and room = '" . $_POST["myRoom"] . "' and mstatus in('Y','N')";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
$sql_meeting2 = "select count(*) as count_meeting from meeting_list where '" . $_POST["myDate1"] . " " . $time1 . "' between concat(strdate,' ',strtime) and concat(enddate,' ',endtime)";
$query_meeting2 = mysql_query($sql_meeting2);
$result_meeting2 = mysql_fetch_array($result_meeting2);
$sql_meeting3 = "select count(*) as count_meeting from meeting_list where '" . $_POST["myDate2"] . " " . $time1 . "' between concat(strdate,' ',strtime) and concat(enddate,' ',endtime)";
$query_meeting3 = mysql_query($sql_meeting3);
$result_meeting3 = mysql_fetch_array($result_meeting3);
$count_meeting = $objResult["count_meeting"] + $result_meeting2["count_meeting"] + $result_meeting3["count_meeting"]; */
$sql_meeting1 = "select count(*)as count_meeting
from meeting_list
where (concat(strdate,' ',strtime)< '" . $_POST["myDate1"] . " " . $time1 . "') and (concat(enddate,' ',endtime) >'" . $_POST["myDate1"] . " " . $time1 . "')";
$query_meeting1 = mysql_query($sql_meeting1);
$result_meeting1 = mysql_fetch_array($query_meeting1);
$sql_meeting2 = "select count(*)as count_meeting
from meeting_list
where (concat(strdate,' ',strtime)< '" . $_POST["myDate2"] . " " . $time2 . "') and (concat(enddate,' ',endtime) >'" . $_POST["myDate2"] . " " . $time2 . "')";
$query_meeting2 = mysql_query($sql_meeting2);
$result_meeting2 = mysql_fetch_array($query_meeting2);
//echo "<p style = 'color:#FF3333'>" . $result_meeting1["count_meeting"] . "</p>";
$count_meeting = $result_meeting1["count_meeting"] + $result_meeting2["count_meeting"];
if ($_POST["myDate1"] > $_POST["myDate2"])
{
if ($time1 > $time2)
{
echo "<p style = 'color:#FF3333'>กรุณาเลือกเวลาให้ถูกต้อง! </p>";
}
else
{
echo "<p style = 'color:#FF3333'>กรุณาเลือกวันให้ถูกต้อง! </p>";
}
}
else
{
if ($count_meeting > 0)
{
echo "<p style = 'color:#FF3333'>ห้องไม่ว่าง มีคนจองแล้ว!!! </p>";
}
else
{
echo "<p style = 'color:#2fb510'>ห้องว่าง สามารถจองได้!!!</p>";
}
}
?>
Tag : PHP, HTML, CSS, HTML5, JavaScript, jQuery
|
|
|
|
|
|
Date :
2018-07-04 15:21:39 |
By :
supername |
View :
544 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณครับ การเขียน Code Check ค่าซ้ำหลักการก็เหมือนกันหมด มี Formation เหมือนๆกันเช่น
1. Select * from where date = '5-7-2018' and TimeStart = '10:30' and TimeEnd = '11:30'
2. query และ mysqli_num_row or Count sql
if($numchk > 0){
echo "ซ้ำ";
} else{
do some thing to insert
}
แค่นี้เองครับ โครตง่าย
/// คำค้นหา php check Duplicate , php check ค่าซ้ำ , www.devbanban.com
|
|
|
|
|
Date :
2018-07-05 08:11:15 |
By :
Hararock |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|