<?php
$less="";
$found=0;
$resultp = mysqli_query($con,"SELECT sc.synd,sc.pmp,sc.kathigitis  FROM syndidaskalies as s,syndcodes as sc WHERE s.mitroo='$mitroo' and sc.syndid=s.syndid");
$c1=mysqli_num_rows($resultp);
if ($c1 > 0 ) 
{

while ($row4 = mysqli_fetch_array($resultp) AND $found==0) 
 {
	      $name=$row4['kathigitis'];
		  $pmpx=$row4['pmp'];
	      $less=rtrim(ltrim($row4['synd']));
		  $sqly = mysqli_query($con,"SELECT id,($day1) FROM dailytab WHERE pmp='$pmpx' 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 dailytab WHERE id='$nid'  " ); 
               $row3 = mysqli_fetch_array($res1); 
	           $mathima= $row3["$day1"];
			   $found=1;
	 	  }
 }
}
     
if ($found==0)
{
	
	 $resultx = mysqli_query($con,"SELECT id,pmp,Teacher,($day1)  FROM dailytab WHERE ($day1)='$tmima' ");
	 $c=mysqli_num_rows($resultx);
	 $rowx = mysqli_fetch_array($resultx);
	 $name=$rowx['Teacher'];
	 $pmpx=$rowx['pmp'];
	 $less=$rowx["$day1"];
	 $id=$rowx['id'];$nid=$id+1;
	 $res1 = mysqli_query($con,"SELECT * FROM dailytab WHERE id='$nid'  " ); 
     $row3 = mysqli_fetch_array($res1); 
	 $mathima= $row3["$day1"];	
}
	 
