<?php
$m1=0;
while ($rowm=mysqli_fetch_array($result1))
{
   $m1++;
   $mathima1[$m1]=$rowm['mathima'];
}

$i=1;
while($row = mysqli_fetch_array($result))
{
	$bathmosa1[$i]=$row['bathmosa']; 
	$bathmosb1[$i]=$row['bathmosb'];
	$exet1[$i]=$row['exetasi'];
	$i++;
}
if (count($bathmosa1) > 0) $avga=array_sum($bathmosa1)/count($bathmosa1);
if (count($bathmosb1) > 0) $avgb=array_sum($bathmosb1)/count($bathmosb1);
$exet1=array_filter($exet1);
if (count($exet1) > 0) $avexet=array_sum($exet1)/count($exet1);
echo "<table class='myTable' >
<tr style='border:1px solid black' bgcolor='#d6ff73'  >
<th>No.</th>
<th>ΜΑΘΗΜΑ</th>
<th>ΤΕΤΡΑΜΗΝΟ Α</th>
";
for ($i=1;$i<=$m1;$i++)
{	
  echo "<tr>";
  echo "<td>". $i;
  echo "<td>". $mathima1[$i];
  echo "<td>"."<p align=right>".number_format($bathmosa1[$i],2)."</td>";
  
}
echo "</tr>";
echo "<tr>";
echo "<td colspan=2>"."<p style='color: red;align=right'>"."ΜΕΣΟΙ ΟΡΟΙ";
echo "<td>"."<p style='color: red' align=right>".number_format($avga,2)."</td>";

echo "</tr>";
			echo "</table>";