<?php
$sql=mysqli_query($con,"SELECT * FROM amivallages where date='$dt'");
$n=mysqli_num_rows($sql);
for ($i=1;$i<=$n;$i++)
{
	$row=mysqli_fetch_array($sql);
	$idtse=$row['idtse'];
	$idtapo=$row['idtapo'];
	$math=$row['mathima'];
	$tm=$row['tmima'];
	if (empty($idtapo))
	{
	    $tprog[$idtse][$row['period']]=$tm;	
	}
	else
	{
	   $temp=$tprog[$idtapo][$row['period']];
	   $tprog[$idtapo][$row['period']]="";
	   $tprog[$idtse][$row['period']]=$temp;
	}
	$roomx=$row['room'];
	
	
	$idtse=$idtse+1;
	$idtapo=$idtapo+1;
	$ar = explode("/",$tprog[$idtapo][$row['period']]);
	$tprog[$idtapo][$row['period']]="";
	if ($roomx <> 0 or $roomx <>""){$rm=$roomx;} else {$rm=$ar[0];}
	
	$tprog[$idtse][$row['period']]=$rm."/".$math;
}