<?php
   
$less="";$room="";
$found=0;
//$nper=$per;
$resultp = mysqli_query($con,"SELECT synd,kathigitis  FROM syndidaskalies WHERE pmp='$mitroo'");
$c1=mysqli_num_rows($resultp);
if ($c1 > 0 ) 
{
while ($row4 = mysqli_fetch_array($resultp) AND $found==0) 
 {
	      $name=$row4['kathigitis'];
	      $less=rtrim(ltrim($row4['synd']));
		  $sqly = mysqli_query($con,"SELECT id,($day1) FROM timetable WHERE Teacher='$name' AND ($day1)='$less'") ;
	      $c=mysqli_num_rows($sqly);
		  if ($c > 0) 
		  {
		       $rowy = mysqli_fetch_array($sqly);
		       $id=$rowy['id'];$nid=$id+1;
	           $res1 = mysqli_query($con,"SELECT ($day1) FROM timetable WHERE id='$nid'  " ); 
               $row3 = mysqli_fetch_array($res1); 
	           $room= $row3["$day1"];
			   $found=1;
	 	  } 
 }
}
     
if ($found==0)
	 {

	 $resultx = mysqli_query($con,"SELECT id,Teacher,($day1)  FROM timetable WHERE ($day1)='$tmima' ");
	 $c=mysqli_num_rows($resultx);
	 $rowx = mysqli_fetch_array($resultx);
	 $name=rtrim(ltrim($rowx['Teacher']));
	 $less=rtrim(ltrim($rowx["$day1"]));
	 $id=$rowx['id'];$nid=$id+1;
	 $teach=$name;
	 $res1 = mysqli_query($con,"SELECT * FROM timetable WHERE id='$nid'  " ); 
     $row3 = mysqli_fetch_array($res1); 
	 $room= $row3["$day1"];
	 
}
	 
