<?php	
$sql = mysqli_query($con,"SELECT dateout, period, COUNT(kath) as tkath FROM apousies WHERE kath>0  GROUP BY dateout,period " );	
echo "<br>"."ΚΑΘΥΣΤΕΡΗΣΕΙΣ ΑΝΑ ΗΜΕΡΑ ΚΑΙ ΠΕΡΙΟΔΟ ΔΙΔΑΣΚΑΛΙΑΣ"."<br>";
// Print out result
$row = mysqli_fetch_array($sql);
$c=mysqli_num_rows($sql);
if ($c > 0){
echo "<table style='width:400px' class='myTable' >
<tr style='border:1px solid black' bgcolor='#66CC99' >
<th>α/α</th>
<th>Ημερομηνία</th>
<th>Περ1</th>
<th>Περ2</th>
<th>Περ3</th>
<th>Περ4</th>
<th>Περ5</th>
<th>Περ6</th>
<th>Περ7</th>
</tr>";
$k=1;
while(!empty($row)) {
	$j=1;
    while($j<=7){$per1[$j]=0;$j++;}
	  $hmera=$row['dateout'];
      while ($hmera==$row['dateout']){
	     $per1[$row['period']]=$row['tkath'];
	     $row = mysqli_fetch_array($sql);
		 }
     $i=1;
     echo "<td>" .$k."</td>";
     echo "<td>". $hmera . "</td>";
     while($i<=7){
		 echo "<td>". $per1[$i] . "</td>";$i++;}
     echo "</tr>";
     $k++;
}
echo "</table>";	 
}