<?php 
    $sqlz = $dbcon->prepare("SELECT pmp,Teacher FROM timetable WHERE id = ? ");
	$sqlz->execute([$tidx]);
	$rowz=$sqlz->fetch(PDO::FETCH_ASSOC);
	$kath=$rowz['Teacher'];
	$pmp1=$rowz['pmp'];
	$sqlz = $dbcon->prepare("SELECT synd FROM syndcodes WHERE pmp = ? and synd=? ");
	$sqlz->execute([$pmp1,$mix]);
	$count=$sqlz->rowCount();
	$sql1 = mysqli_query($con,"SELECT MAX(syndid) as mid FROM syndcodes ");
	$row1=mysqli_fetch_array($sql1);
	$lid=$row1['mid']+1;
	if ($count == 0)
	{
	  $sqlx = $dbcon->prepare("INSERT INTO syndcodes (syndid,kathigitis,synd,pmp) values (?,?,?,?) ");
	  $sqlx->execute([$lid,$kath,$mix,$pmp1]);
	  $arr=explode("@",$mix);
	  $nx=count($arr);
	  for ($j=0;$j<$nx;$j++)
	  {
		$x=rtrim(ltrim($arr[$j]));
		$sql1 = mysqli_query($con,"SELECT mitroo FROM allstudentinfo WHERE tmima='$x' ORDER by eponimo,onoma " );
		if (mysqli_num_rows($sql1) == 0)
		{
			
          $sql1 = mysqli_query($con,"SELECT  s.mitroo FROM syndidaskalies as s,allstudentinfo as a, syndcodes as c 
          WHERE c.synd = '$x' AND s.mitroo=a.mitroo and s.syndid=c.syndid ORDER BY a.eponimo,a.onoma");	
        }
       
		while ($rowall = mysqli_fetch_array($sql1))
		{
		  $mitr=$rowall['mitroo'];
		  $sqlx = $dbcon->prepare("INSERT INTO syndidaskalies (syndid,mitroo) values (?,?) ");
	      $sqlx->execute([$lid,$mitr]);
		  
		}
	  }
    }	  
	  
