<?php
   
	 $mathimax="";
	 
	  $found=0;
	  $sqlx = "SELECT synd,kathigitis  FROM syndidaskalies WHERE pmp='$mitroo'";
      $result1 = mysqli_query($con,$sqlx);
	  $c1=mysqli_num_rows($result1);
	  if ($c1 > 0 ) 
	  {
	  
while ($row4 = mysqli_fetch_array($result1)) 
 {
	      $name=$row4['kathigitis'];
	      $less=$row4['synd'];
		  $teach=$name;
		 
           include "mprog.php";
		  		  //'''''''''''''''''
          $res = mysqli_query($con,"SELECT id,($day1) FROM t1 WHERE Teacher='$name' AND ($day1)='$less' " ); 
          $c=mysqli_num_rows($res);
		  if ($c > 0) {
		    $row2 = mysqli_fetch_array($res);
			$mathimax=$row2["$day1"];
			$id=$row2["id"]; $nid=$id+1;
	        $res1 = mysqli_query($con,"SELECT * FROM t1 WHERE id='$nid'  " ); 
            $row3 = mysqli_fetch_array($res1); 
	        $room= $row3["$day1"];
			$found=1;
			break 1;
	   	    }
	     }
	  }
     
	 if ($found==0)
	 {
	 $taxi=mb_substr($tmima, 0, 1, 'utf-8');
	 $tm3a=$taxi;
	 $tm3b=mb_substr($tmima, 2, 1, 'utf-8');
	 $tm3=$tm3a.$tm3b;
	 
	 $sql = "SELECT id,Teacher,($day1)  FROM timetable WHERE ($day1)='$tmima' OR (($day1) LIKE '$tm3%' ) ";
	 $result = mysqli_query($con,$sql);
	 $c=mysqli_num_rows($result);
	 $rowx = mysqli_fetch_array($result);
	 $name=$rowx['Teacher'];
	 
	 $mathimax=$rowx["$day1"];
	 $id=$rowx['id'];$nid=$id+1;
	 $teach=$name;
	 echo $teach.$c.$oldname;
	 include "mprog.php";
	 $res1 = mysqli_query($con,"SELECT * FROM t1 WHERE id='$nid'  " ); 
     $row3 = mysqli_fetch_array($res1); 
	 $room= $row3["$day1"];
	 if ($c == 2 AND $name==$oldname AND $taxi=='Α') {
		$rowx = mysqli_fetch_array($result);
		$name=$rowx['Teacher'];
		$mathimax=$rowx["$day1"];
		$id=$rowx['id']; $nid=$id+1;
		$teach=$name;
		 echo $teach."in".$c." ";
		include "mprog.php";
	       $res1 = mysqli_query($con,"SELECT * FROM t1 WHERE id='$nid'  " ); 
           $row3 = mysqli_fetch_array($res1); 
	       $room= $row3["$day1"];	
		} 
	 		 
	 }
	 
