<?php
include_once("connection.php"); 
if (!empty($_POST['sid'])) {

$sid = $_POST['sid'];
$queryls1q = "select * from therapy_chart where date='$sid'";
$resultls1q  = mysqli_query($conn,$queryls1q);	
while($row=mysqli_fetch_array($resultls1q))
{
$day =  $row['day'];
$timing = $row['timing'];
}
 
 $queryleadqf="update therapy_chart_more set search_date='$sid'  where 1";
$resultleadqf=mysqli_query($conn,$queryleadqf);
 
?>

<label>Therapy Chart</label><br />
<table border = "1" cellpadding="0" cellspacing="0" style="border-collapse:collapse;" width="100%" class="table table-striped table-bordered dt-responsive nowrap">
<thead>
<tr>
<th><div align="left" style="padding:3px; font-size:13px;  color:#000000">Timing</div></th>
<th><div align="left" style="padding:3px; font-size:13px;  color:#000000"><?php echo $day?></div></th>
</tr>
</thead><?php 
$i=1;
$queryls1 = "select * from therapy_chart_more where appointment_date='$sid'";
$resultls1  = mysqli_query($conn,$queryls1);	
while($row=mysqli_fetch_array($resultls1))
{
$patient_name = $row['patient_name'];
$therapy_name = $row['therapy_name'];
$therapist_name =  $row['therapist_name'];
$appointment_time = $row['appointment_time'];
$room_no = $row['room_no'];
?>


<tr style="font-size: 13px;">
<td><div align="left" style="padding:3px; font-size:13px;  color:#000000"><?php echo $timing;?><br /><?php echo $room_no?></div></td>
<td><div align="left" style="padding:3px; font-size:13px;  color:#000000"><?php echo $therapist_name?><br /><?php echo $patient_name?><br /><?php echo $therapy_name?></div></td>
</tr><?php } ?>

</table>
<?php 
}elseif (!empty($_POST['sid1'])) {

$query = "select * from therapy_chart_more";
$result  = mysqli_query($conn,$query);	
while($row=mysqli_fetch_array($result))
{
$search_date = $row['search_date'];
}


    $sid1 = $_POST['sid1'];

    $query2 = "select * from  therapy_chart_more where room_no='$sid1' and appointment_date='$search_date'";
    $result2 = mysqli_query($conn, $query2);
    if ($result2->num_rows > 0) {
	echo '<select  class="form-control" data-style="py-0" name="timing"  required>';
	 echo '<option value=""  selected="selected">Select Time Slot</option>';
        while ($row = mysqli_fetch_assoc($result2)) {
		$appointment_time = $row['appointment_time'];
		
$querynp = "select * from time_slot where time_slot!='$appointment_time'";
$resultmp = mysqli_query($conn,$querynp);
while($row=mysqli_fetch_array($resultmp))
{
$time_slot = $row['time_slot'];

echo '<option value="' . $row['time_slot'] . '">' . $row['time_slot'] . '</option>';


    }

	}echo '</select>';	
	}else{
	
	echo '<select  class="form-control" data-style="py-0" name="timing"  required>';
	 echo '<option value=""  selected="selected">Select Time Slot</option>';
		
$querynp = "select * from time_slot";
$resultmp = mysqli_query($conn,$querynp);
while($row=mysqli_fetch_array($resultmp))
{
$time_slot = $row['time_slot'];

echo '<option value="' . $row['time_slot'] . '">' . $row['time_slot'] . '</option>';

}echo '</select>';	
	
	}



}

?>
