ถามเรื่องจองห้องประชุมหน่อยครับ

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา ถามเรื่องจองห้องประชุมหน่อยครับ

ถามเรื่องจองห้องประชุมหน่อยครับ
ผมทำระบบจองห้องประชุมและติดปัญหาครับ ระบบจองห้องประชุมนี้ user สามารถจองและยกเลิกห้องประชุมเองได้ แต่เมื่อคนจองยกเลิกห้องไปแล้ว ผู้ที่มาจองใหม่วันเดียวกันเวลาเดียวกัน มีปุ่ม check ว่าห้องว่างหรือเปล่า กลับขึ้นแจ้งว่า "ห้องไม่ว่าง มีคนจองแล้ว!"

reservation.php
		<script type="text/jscript">
		$(document).ready(function() {
			$('a.button1').click(function() {
				
						//Getting the variable's value from a link 
				var loginBox = $(this).attr('href');

				//Fade in the Popup
				$(loginBox).fadeIn(300);
				
				//Set the center alignment padding + border see css style
				var popMargTop = ($(loginBox).height() + 24) / 2; 
				var popMargLeft = ($(loginBox).width() + 24) / 2; 
				
				$(loginBox).css({ 
					'margin-top' : -popMargTop,
					'margin-left' : -popMargLeft
				});
				
				// Add the mask to body
				$('body').append('<div id="mask"></div>');
				$('#mask').fadeIn(300);
				
				return false;
			});
			
			// When clicking on the button close or the mask layer the popup closed
			$('a.close, #mask').live('click', function() { 
			  $('#mask , .login-popup').fadeOut(300 , function() {
				$('#mask').remove();  
			}); 
			return false;
			});
		});
		</script>
		<script language="JavaScript">
		   var HttPRequest = false;

		   function doCallAjax() {
			  HttPRequest = false;
			  if (window.XMLHttpRequest) { // Mozilla, Safari,...
				 HttPRequest = new XMLHttpRequest();
				 if (HttPRequest.overrideMimeType) {
					HttPRequest.overrideMimeType('text/html');
				 }
			  } else if (window.ActiveXObject) { // IE
				 try {
					HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
				 } catch (e) {
					try {
					   HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {}
				 }
			  } 
			  
			  if (!HttPRequest) {
				 alert('Cannot create XMLHTTP instance');
				 return false;
			  }
		
				var url = 'data_post.php';
				var pmeters = "myRoom=" + encodeURI( document.getElementById("txtRoom").value) +
	"&myDate1=" + encodeURI( document.getElementById("id_datetime_picker0").value ) +
	"&myDate2=" + encodeURI( document.getElementById("id_datetime_picker1").value ) ;
				
				//var pmeters = 'myName='+document.getElementById("txtName").value '&my2='; // 2 Parameters
				HttPRequest.open('POST',url,true);

				HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				HttPRequest.setRequestHeader("Content-length", pmeters.length);
				HttPRequest.setRequestHeader("Connection", "close");
				HttPRequest.send(pmeters);
				
				
				HttPRequest.onreadystatechange = function()
				{

					 if(HttPRequest.readyState == 3)  // Loading Request
					  {
					   document.getElementById("mySpan").innerHTML = "Now is Loading...";
					  }

					 if(HttPRequest.readyState == 4) // Return Request
					  {
					   document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
					  }
					
				}

				/*
				HttPRequest.onreadystatechange = call function .... // Call other function
				*/

		   }
		</script>

									<form class="form-horizontal" method="post" action="add_meeting_list.php" id="add_meeting">
										<div class="form-group">
											<label class="col-sm-2 control-label" for="umpire_position">&nbsp;</label>
											<div class="col-sm-4">&nbsp;</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label" for="umpire_position">วันที่จอง</label>
											<div class="col-sm-3">
												<div class="input-group">
													<input type="text" data-date-format="yyyy-mm-dd" data-date-viewmode="years" class="form-control" id="id_datetime_picker0" name="date1">
													<span class="input-group-addon"> <i class="fa fa-calendar"></i> </span>
												</div>
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label" for="umpire_position">ถึงวันที่</label>
											<div class="col-sm-3">
												<div class="input-group">
													<input type="text" data-date-format="yyyy-mm-dd" data-date-viewmode="years" class="form-control" id="id_datetime_picker1" name="date2">
													<span class="input-group-addon"> <i class="fa fa-calendar"></i> </span>
												</div>
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label" for="umpire_position">ห้องประชุม</label>
											<div class="col-sm-3">
											<? 
												$strSQL2 = "select * from meeting_room";
												$objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
											?>
												<select name="txtRoom" id="txtRoom" class="form-control">
												<?
												while($objResult2 = mysql_fetch_array($objQuery2))
												{	
												?>
												<option value='<?=$objResult2["id"];?>'><?=$objResult2["name"];?></option>
												<? 
												}
												?>
												</select>
											</div>
											<label class="col-sm-1 control-label" for="umpire_position">เพื่อใช้</label>
											<div class="col-sm-2">
											<? 
												$strSQL3 = "select * from meeting_room_type";
												$objQuery3 = mysql_query($strSQL3) or die ("Error Query [".$strSQL3."]");
											?>
												<select name="txtRoomtype" id="form-field-select-1" class="form-control">
												
												<?
												while($objResult3 = mysql_fetch_array($objQuery3))
												{	
												?>
												<option value='<?=$objResult3["id"];?>'><?=$objResult3["name"];?></option>
												<? }
												?>
												</select>
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label" for="umpire_position"></label>
											<div class="col-sm-2"><input type="button" class="form-control" value="ตรวจสอบ" onClick="JavaScript:doCallAjax();"></div>
											<div class="col-sm-5"><strong><span id="mySpan" style="color:#FF3333; font-size:20px">คลิ๊กเพื่อตรวจสอบห้องประชุมก่อนนะครับ</span></strong></div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label" for="umpire_position">หัวข้อการประชุม</label>
											<div class="col-sm-6">
												<input type="text" class="form-control" name="txtName" required="required"/>
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label" for="umpire_position">ดำเนินการ</label>
											<div class="col-sm-5">
													<label class="radio-inline">
														<input type="radio" class="square-black" name="rdoConduct" value="Y" checked> ผู้จัดรับผิดชอบดำเนินการเอง
													</label>
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label" for="umpire_position">งบประมาณ</label>
											<div class="col-sm-5">
												<div class="radio">
													<label>
														<input type="radio" value="1" name="rdoBudget" class="square-black" checked>
														ไม่เสียงบประมาณ(ประชุมภายในบริษัท ขอเฉพาะน้ำดื่ม)
													</label>
												</div>
												<div class="radio">
													<label>
														<input type="radio" value="2" name="rdoBudget" class="square-black">
														ไม่เสียงบประมาณ(ประชุมภายในบริษัท ขอเฉพาะน้ำดื่มและเสริฟอาหาร)
													</label>
												</div>
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label" for="umpire_position">&nbsp;</label>
											<div class="col-sm-6">
												       <label style="font-size:12px;"><a href="#">กรุณาลงทะเบียนขอใช้ห้องประชุมล่วงหน้าก่อนประมาณ 3 วัน เพื่อความสะดวกในการจัดเตรียมห้องประชุม<br/></a></label>
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label" for="umpire_position"></label>
											<div class="col-sm-9">
												<input type="submit" class="btn btn-bricky" value="ตกลง">
											</div>
										</div>
										<div class="form-group">
											<label class="col-sm-2 control-label" for="umpire_position">&nbsp;</label>
											<div class="col-sm-4">&nbsp;</div>
										</div>
									</form>

data_check.php
<?
	include("connectdb.php");


	$strSQL = "SELECT * FROM meeting_list WHERE ((strdate between '".$_POST["myDate1"]."' and '".$_POST["myDate2"]."') or ";
	$strSQL .= " (enddate between '".$_POST["myDate1"]."' and '".$_POST["myDate2"]."')) and ";
	$strSQL .= " room = '".$_POST["myRoom"]."' and mstatus in('Y','N') ";
	$objQuery = mysql_query($strSQL);
	$objResult = mysql_fetch_array($objQuery);
	if($objResult)
	{
		echo "ห้องไม่ว่าง มีคนจองแล้ว!";
	}
	else
	{
		echo "ห้องว่าง สามารถจองได้!";
	}

?>
add_meeting_list.php
<? session_start();
	error_reporting(0);
?>
<html>
<head>
<title>ระบบจองห้องประชุม</title>
<meta HTTP-EQUIV="Refresh" CONTENT="1;URL=home.php" charset="utf-8">
<link rel="shortcut icon" href="stylesheet/img/devil-icon.png"> <!--Pemanggilan gambar favicon-->
<link rel="stylesheet" type="text/css" href="mos-css/mos-style.css"> <!--pemanggilan file css-->
</head>

<body>
<div id="errorForm"><br><br>
		<div class="informasi">

<?
	include("connectdb.php");
	
	if(trim($_POST["txtName"]) == "")
	{
		echo "กรุณาระบุหัวข้อการประชุม!";
		exit();	
	}
		
			
	$strSQL = "SELECT * FROM meeting_list WHERE ((strdate between '".$_POST["date1"]."' and '".$_POST["date2"]."') or ";
	$strSQL .= " (enddate between '".$_POST["date1"]."' and '".$_POST["date2"]."')) and ";
	$strSQL .= " room = '".$_POST["txtRoom"]."' and mstatus in('Y','N') ";
	$objQuery = mysql_query($strSQL);
	$objResult = mysql_fetch_array($objQuery);
	if($objResult)
	{
			echo "วันและเวลาที่จองห้องของคุณ ถูกจองไปแล้ว!";
	}
	else
	{	
		
		$strSQL1 = "INSERT INTO meeting_list ";
		$strSQL1 .=" (id,strdate,enddate,room,room_type,name,user,conduct,budget,mstatus) ";
		$strSQL1 .=" VALUES (NULL,'".$_POST["date1"]."','".$_POST["date2"]."','".$_POST["txtRoom"]."','".$_POST["txtRoomtype"]."' ";
		$strSQL1 .=" ,'".$_POST["txtName"]."','".$_SESSION['member_name']."','".$_POST["rdoConduct"]."' ";
		$strSQL1 .=" ,'".$_POST["rdoBudget"]."','Y')";
		$objQuery1 = mysql_query($strSQL1);
		
		echo "จองห้องประชุมเรียบร้อยแล้ว !";		
	
	}

	mysql_close();
?>

		</div>
</div>
</body>
</html>


Pusirinon 110.170.246.xxx 31-03-2015 15:07:38

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
โทษทีครับ ไฟล์ data_check.php คือ data_post.php ครับผม


pusirinon 110.170.246.xxx 31-03-2015 15:12
 ความคิดเห็นที่ 2
ถ้าโค้ดไม่ผิด แต่เงื่อนไขคำสั่ง sql ไม่ตรงตามที่ต้องการ ก็ต้องไปไล่ดูว่าค่านั้น ใช่เงื่อนไขที่ต้องการหรือไม่
ลอง echo $strSQL; แล้วเอาค่านี้ไปรันใน phpmyadmin ตรง sql ดู

ปํญหาน่าจะเป็นจากข้อมูล หรือรูปแบบเงื่อนไขการเรียกข้อมูล เช่น between น่าจะหมายถึง >= และ <= (ถ้าจำไม่ผิด)
แต่ถ้าค่าเราไม่ต้องการ = อาจจะไปใช้ x>'datetime1' AND x<'datetime2'  


ninenik 171.96.23.xxx 31-03-2015
 ความคิดเห็นที่ 3
ถ้าอยากได้ SQL ประมาณนี้ต้อง


pusirinon 110.170.246.xxx 01-04-2015 08:57
 ความคิดเห็นที่ 4
พอเขียนเป็น SQL แล้วจะประมาณนี้ใช่หรือเปล่าครับ
	$strSQL = "SELECT * FROM meeting_list WHERE ((strdate between '".$_POST["date1"]."' and '".$_POST["date2"]."') or ";
	$strSQL .= " (enddate between '".$_POST["date1"]."' and '".$_POST["date2"]."') or ";
	$strSQL .= " ('".$_POST["date1"]."' between strdate and enddate) or ";
	$strSQL .= " ('".$_POST["date2"]."' between strdate and enddate)) and ";
	$strSQL .= " room = '".$_POST["txtRoom"]."' and mstatus in('Y','N') ";


pusirinon 110.170.246.xxx 01-04-2015 10:00
 ความคิดเห็นที่ 5
ลองดูเป็นแนวทาง

ให้ 08:15 - 16:15  strdate,enddate ให้เป็น x กับ y
ถ้ารับค่าสองค่า เป็นเวลา เริ่มและเวลาสิ้นสุด  
$_POST["date1"]  $_POST["date2"] .ให้เป็น a  กับ b 
คำสั่ง sql
where 
(x>a and x>b) or
(y<a and y<b)


>>>  อัพเดท >>> 01-04-2015
------------------------------------------
แนวทางเช็คห้องว่าง ด้วย php และ mysql กับช่วงเวลาต่อวัน 


ninenik 171.96.23.xxx 01-04-2015
 ความคิดเห็นที่ 6
ขอบคุณมาครับ


pusirinon 110.170.246.xxx 01-04-2015 11:21
1






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ