<?php
mysqli_query($con,'TRUNCATE TABLE dailytab;');
$ta="";
$cols="id,pmp,Teacher,";
for ($i=1;$i<=$gymx;$i++){$ta.="day".$i.',';}
$cols=$cols.$ta;
$cols = " (".rtrim($cols, ',').") ";
$ta="";	
$all="id,pmp,Teacher,";
for ($i=1;$i<=$gymx;$i++){$t=$day.$i;$ta.=$t.',';}
$all=$all.$ta;
$all = rtrim($all, ',');

mysqli_query($con,"INSERT INTO dailytab ".$cols. " SELECT ".$all." FROM timetable");