   <?php
$idapon=$pmpapon=$kathapon=array();

$sql=mysqli_query($con,"SELECT t.id,t.pmp,t.Teacher FROM dailytab as t,apousieskath as a 
where t.pmp=a.pmp and (a.datefrom <= '$dt' and a.dateto >='$dt')");
$i=0;
while($row=mysqli_fetch_array($sql))
{
	$i++;
	$idapon[$i]=$row['id'];
	$pmpapon[$i]=$row['pmp'];
	$kathapon[$i]=$row['Teacher'];
}
$tk=$i;
$tidx=array();
echo "<table style='width:900px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73' >
<th>Α/Α</th>
<th>Εκπαιδευτικός</th>";
for ($i=1;$i<=$gym;$i++)
{
	$titep="Περίοδος ".$i;
	echo "<th>".$titep."</th>";
}
echo "</tr>";
for ($ka=1;$ka<=$tk;$ka+=2)
{
   $fil=array();
   echo "<tr>";//first row
   echo "<td>".$ka. "</td>";
   echo "<td>"."<font face='arial' size='2pt'>".$kathapon[$ka]." (".$idapon[$ka].")"."</td>";
   for ($i=1;$i<=$gym;$i++)
   {
	    $dayper="day".$i;
		$sql=mysqli_query($con,"SELECT ".$dayper.",id FROM dailytab where id='$idapon[$ka]' ");
		$row=mysqli_fetch_array($sql);
		$tmi=$row["$dayper"];
		if (!empty($tmi))
		{
			$fil[$i]=1;
			$id=$row['id'];
			$nid=$id+1;
			$res1 = mysqli_query($con,"SELECT ($dayper) FROM dailytab WHERE id='$nid'  " ); 
			$row3 = mysqli_fetch_array($res1); 
			$ar= explode("/",$row3["$dayper"]);
			$room=$ar[0];
			echo "<td>" ."<font face='arial' size='2pt'>"."<b>". $row["$dayper"]."</b>"."(".$room.")". "</td>";	
		}
		else {
			$fil[$i]=0;
			echo "<td>" ." ". "</td>";
		}		
   }
   echo "</tr>";
   echo "<tr>";
   echo "<tr>"; echo "<td>". "   " . "</td>"; echo "<td>". "   " . "</td>";
   $sql=mysqli_query($con, "SELECT t.Teacher,a.tid,a.period,a.pmpapon FROM dailytab as t,anaplirosi as a  
		      WHERE a.aponid=t.id and a.aponid='$idapon[$ka]' and date='$dt' ");
   $taid=array();
   while($row=mysqli_fetch_array($sql))
   {
	  $er=$row['pmpapon'];
	  if (empty($er) or $er=='')
	  {
	    $p=$row['period'];
	    $taid[$p]=$row['tid'];
	  }
   }
   
   for ($i=1;$i<=$gym;$i++)
   {
		$ss=trim($taid[$i]);
		 if ($ss > 0 and $ss < 999 )
		 {
		   $dayper=$day.$i;
		   $sql=mysqli_query($con,"SELECT Teacher FROM dailytab where id='$taid[$i]' ");
		   $row=mysqli_fetch_array($sql);
		   echo "<td>"."<b>"."<font face='arial' size='2pt'>".$row['Teacher']."</b>"."</td>"; 
		 }
		 elseif ($ss==999)
		 {
		    echo "<td>"."<b>"."<font face='arial' size='2pt'>"."ΣΤΟ ΤΜΗΜΑ ΤΟΥΣ"."</b>"."</td>";
		 }
		 elseif ($ss=="!")
		 {
			echo "<td>"."<b>"."<font face='arial' size='2pt'>"."ΠΑΡΩΝ/ΟΥΣΑ"."</b>"."</td>"; 
		 }
		 elseif ($ss=="ΔΔΚ")
		 {
			echo "<td>"."<b>"."<font face='arial' size='2pt'>"."ΕΚΔΗΛΩΣΗ"."</b>"."</td>"; 
		 }
		 else
		 {
		   if($ss==1)
		   {
			echo "<td>"."<b>"."<font face='arial' size='2pt'>"."ΑΛΛΑΓΗ"."</b>"."</td>";   
		   }
		   else
		   {
		   echo "<td>"."<b>"."<font face='arial' size='2pt'>"." "."</b>"."</td>"; 	 
		 } }
		 
	}
	
    echo "</tr>"; 
}
echo "</table>";