我正在开发预订系统。我在数据库中有2个表:
<table border=1><tr><td>booking</td><td>tables</td></tr>
<tr><td>id</td><td>id</td></tr>
<tr><td>booking_date</td><td>masa</td></tr>
<tr><td>booking_hour</td><td>status</td></tr>
<tr><td>booking_table</td><td>color</td></tr>
<tr><td>customer</td></tr>
我尝试做的是首先选择您想要预订餐桌的日期和时间,然后这些餐桌将根据预订表中的其他预订更新其状态。我不知道的是如何验证与其他预订一起选择的日期和时间并更新表格。
$status='';
$result = mysqli_query($connector,"SELECT * from booking");
$result2 = mysqli_query($connector,"SELECT * from tables");
echo"
<form method='post' action='booking.php' id=''>
<label>Choose a date:</label>
<p><input class='form-control' type='text' name='datepicker' id='datepicker'></p>
<label>Choose a period of time:</label>
<select class='form-control form1' type='text' name='timepicker'>
<option value='810'>8:00-10:00</option>
<option value='1012'>10:00-12:00</option>
<option value='1214'>12:00-14:00</option>
<option value='1416'>14:00-16:00</option>
<option value='1618'>16:00-18:00</option>
<option value='1820'>18:00-20:00</option>
<option value='2022'>20:00-22:00</option>
</select>
<div class='btn-group' role='group' align='center'>
<table align='center'>
<tr>";
if(isset($datepicker) && isset($timepicker)){
$count4 = mysqli_num_rows($result);
if($count4 == "0"){
$output = '<h2>No result found!</h2>';
}else{
$count = mysqli_num_rows($result2);
if($count == "0"){
$output = '<h2>No result found!</h2>';
}else{
while($row = mysqli_fetch_array($result2)){
$status = $row['status'];
$tableid = $row['masa'];
$color = $row['color'];
if($tableid == 't1' ){
echo"<td><input type='button' class='btn btn-secondary' value='$status' name='t1' style='width:60px; height: 50px;margin:15px 5px 5px 0px;background-color:$color;font-size:9px'></td>";
}
if($tableid == 't2' ){
echo"<td><input type='button' class='btn btn-secondary' value='$status' name='t2' style='width:60px; height: 50px;margin:15px 5px 5px 0px;background-color:$color;font-size:9px'></td>";
}
更新: 我设法这样做了:
$result = mysqli_query($connector,"SELECT * from booking");
$result2 = mysqli_query($connector,"SELECT masa from tables");
$datepicker = $_POST['datepicker'];
$color='';
$busy=array();
echo"
<form method='post' action='booking.php' id=''>
";
if(isset($datepicker)){
while($row=mysqli_fetch_array($result)){
$booking=$row['booking_table'];
$date = $row['booking_date'];
$datecheck = date("d-m-Y", strtotime($date));
if($datepicker == $datecheck){
array_push($busy,$row['booking_table']);
}
}
while($row2=mysqli_fetch_array($result2)){
$tableid=$row2['masa'];
if(in_array($tableid, $busy)){
$status='Booked';
$color='red';
$read='readonly';
}
else{
$status='Free';
$color='green';
$read='';
}
echo"<td width='50%'><input type='button' class='btn btn-secondary' value='$status' name='$tableid' style='width:60px; height: 50px;margin:15px 5px 5px 0px;background-color:$color;font-size:9px' $read></td>";
}
}