<?php
include "scrinit.php";
include "logo.php";
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid black;padding:2px;font-size:11px; }
<p style="font-size:11px;"></p>
</style>


</head>
<body  style="width:995px; margin:0 auto; ">

<?php 
require("dbconnect.php");
$sql=mysqli_query($con,"SELECT  b.*,a.eponimo,a.onoma,a.tmima
     from  blast as b,allstudentinfo as a where b.mathima not like ' %' and b.bathmosa <> 0 and b.bathmosb <> 0 and b.mitroo=a.mitroo order by a.tmima,a.mitroo");

echo "ΑΡΙΣΤΟΙ ΣΧΟΛΕΙΟΥ";
echo "<br>";
echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:16px'  >
<tr>
<th>Α/Α</th>
<th>ΤΜΗΜΑ</th>
<th>ΜΑΘΗΤΗΣ/ΤΡΙΑ</th>
<th>ΟΛΙΚΟ</th>
<th>ΑΡ. ΜΑΘ.</th>
<th>ΜΕΣΟΣ ΟΡΟΣ</th>
</tr>";
$i=0;$ca=0;$cb=0;$cg=0;$aa=0;$ab=0;$ag=0;$k=0;
$row = mysqli_fetch_array($sql);
while(!empty($row) )
{  
   $am=$row['mitroo'];
   $tmima=$row['tmima'];
   $name=$row['eponimo'] ." ".$row['onoma'];
   
   $taxi=mb_substr($tmima, 0, 1, 'utf-8');
   switch ($taxi) 
	   {
		case 'Α':
			$ca++;
			break;
		case 'Β':
			$cb++;
			break;
		case 'Γ':
			$cg++;
			break;
       }   
   $c=0;$sum=0;
   while ($row['mitroo'] == $am )
   {  
      $math=$row['mathima']; 
	  
	  $ba=$row['bathmosa']; 
	  $bb=$row['bathmosb'];
	  $be=$row['exetasi'];
	  
	  if ($be >0 )
	  {
		  $bt=round((($ba+$bb)*0.35+$be*0.3),0);
	  }	
	  else
	  {
		  $bt=round((($ba+$bb)*0.5),0);
	  }
	  $c++;
	  $sum=$sum+$bt;
	  $row = mysqli_fetch_array($sql);
   }
   $mesos=$sum/$c;
   if ($mesos >= 18.5)
   {
	   $k++;
      switch ($taxi) 
	   {
		case 'Α':
			$aa++;
			break;
		case 'Β':
			$ab++;
			break;
		case 'Γ':
			$ag++;
			break;
       }   
   
   echo "<tr>";
   echo "<td>". $k. "</td>";
   echo "<td>". $tmima. "</td>";
   echo "<td>". $name. "</td>";
   echo "<td>". $c. "</td>";
   echo "<td>". round($mesos, 2). "</td>";
   echo "</tr>";
   
   }
   $i++;
}
echo "</table>"; 

if ($ca <> 0){$pa=100*$aa/$ca;}
if ($cb <> 0){$pb=100*$ab/$cb;}
if ($pg <> 0) {$pg=100*$ag/$cg;}
$tot=$row['stus'];
echo "<br>"."ΣΥΝΟΛΟ ΜΑΘΗΤΩΝ : ".$i;
$ta=100*$aa/$i;
$tb=100*$ab/$i;
$tg=100*$ag/$i;
echo "<br>";echo "<br>";
echo "<table class='myTable' >
<tr style='border:1px solid black;font-size:16px'  >
<tr>
<th>ΤΑΞΗ</th>
<th>ΣΥΝΟΛΟ</th>
<th>ΑΡΙΣΤΟΙ</th>
<th>ΠΟΣΟΣΤΟ ΤΑΞΗΣ %</th>
<th>ΠΟΣΟΣΤΟ ΣΧΟΛΕΙΟΥ %</th>
</tr>";
echo "<tr>";
   echo "<td>".'Α'. "</td>";
   echo "<td>".$ca. "</td>";
   echo "<td>".$aa. "</td>";
   echo "<td>".round($pa, 2). "</td>";
   echo "<td>".round($ta, 2). "</td>";
echo "</tr>"; 
echo "<tr>";
   echo "<td>".'Β'. "</td>";
   echo "<td>".$cb. "</td>";
   echo "<td>".$ab. "</td>";
   echo "<td>".round($pb, 2). "</td>";
   echo "<td>".round($tb, 2). "</td>";
echo "</tr>";
echo "<tr>";
   echo "<td>".'Γ'. "</td>";
   echo "<td>".$cg. "</td>";
   echo "<td>".$ag. "</td>";
   echo "<td>".round($pg, 2). "</td>";
   echo "<td>".round($tg, 2). "</td>";
echo "</tr>";  
  
echo "</table>"; 
//***********************

?>	
<br /><br />
<a  href='indexd.php' style="color:blue "  > <button> Επιστροφή στο Μενού  </a>

</body>
</html>