<?php
//************************* prepare column list for query

$ta="";
$cols="id,pmp,Teacher,";
for ($i=1;$i<=$gym;$i++){$ta.="day".$i.',';}
$cols=$cols.$ta;
$cols =rtrim($cols, ',');
//*************************	

$result = mysqli_query($con,"SELECT ".$cols." FROM dailytab ");

$tprog=$teach=$room=$pmpt=array();
$j=0;
while ($row = mysqli_fetch_array($result))
{
   $id=$row['id'];
   $teach[$id]=$row['Teacher'];
   $pmpt[$id]=$row['pmp'];
   for ($i=1;$i<=$gym;$i++) 
   {
      $in="day".$i;
      $tprog[$id][$i]=$row["$in"];
	  if($row["$in"] <>"" AND !($id & 1))
	  {
	  	  $ar=explode("/",$row["$in"]);
		  $j++;
		  $room[$j]=$ar[0];
	  }
   }
}