<?php
session_start();
//$menu = $_SESSION['menu'];
//include $menu;
?>

<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:11pt; }
<p style="font-size:11px;"></p>
</style>



</head>
<body>
<h3> ΟΜΑΔΕΣ ΕΞΕΤΑΖΟΜΕΝΩΝ ΜΑΘΗΜΑΤΩΝ</h3>

<?php 

require("dbconnect.php");
// o pinakas na exei pedia mitroo , exam2,exam3,exam4 (ta 3 exetazomena mathimata ka io mitroo mathiti)
	
$sql = mysqli_query($con,"SELECT DISTINCT exam2 as math FROM dilosimath
UNION 
SELECT DISTINCT exam3 as math FROM dilosimath
UNION
SELECT DISTINCT exam4 as math FROM dilosimath ");

$c=mysqli_num_rows($sql);
echo "<br>"."ΛΙΣΤΑ ΜΑΘΗΜΑΤΩΝ ΠΡΟΣ ΕΞΕΤΑΣΗ: ".$c."<br>";
$i=1;
while ($sq=mysqli_fetch_array($sql)){
	$m=$sq['math']; 
	if ($m <> ""){
	$math[$i]=$m;
	echo $math[$i]."<br>";
	$i++;
	}
}
$i--;
$c=$i;
echo "<br>"."ΣΥΝΟΛΟ ΜΑΘΗΜΑΤΩΝ: ".$c."<br>";

/*
$sql = mysqli_query($con,"SELECT  mitroo as mt  FROM dilosimath where exam2='$math[14]'
UNION 
SELECT mitroo as mt  FROM dilosimath where exam3='$math[14]'
UNION
SELECT mitroo as mt  FROM dilosimath where exam4='$math[14]' ");

$i=1;
while ($sq=mysqli_fetch_array($sql))
{
    $mitr=$sq['mt']; 
	if ($mitr <> ""){
	$mitroo[$i]=$mitr;
	echo $mitroo[$i]."<br>";
	$i++;
	}
}
$i--;

echo "<br>"."ΣΥΝΟΛΟ ΜΑΘΗΤΩΝ: ".$i." ΓΙΑ ΤΟ ΜΑΘΗΜΑ: ".$math[7]."<br>";
//............................................
*/

for ($i=1;$i<=$c;$i++) 
{
$k=1;
$sql=mysqli_query($con,"SELECT mitroo,exam2,exam3,exam4 FROM dilosimath");
while ($sq=mysqli_fetch_array($sql))
{
    $mitr=$sq['mitroo'];
	$l1= $sq['exam2']; 
	$l2= $sq['exam3'];
	$l3= $sq['exam4'];
	$les=$math[$i];
	if ($les == $l1 OR $les == $l2 OR $les == $l3)
	{
	   $exet[$math[$i]][$k]=$mitr;
	   $k++;
	}
}
}

//print_r($exet);

// ΤΟ ΠΡΟΤΟ ΜΑΤΗΙΜΑ ΣΕ ΚΑΤΗΕ ΟΜΑΔΑ ΜΠΟΡΕΙ ΝΑ ΣΙΝΔΙΑΣΤΕΙ ΜΕ ΤΑ ΥΠΟΛΟΙΠΑ
$j=$c--;
for ($k=1;$k<=$j;$k++){
$group[$k]=$math[$k];
for ($i=1;$i<=$c;$i++) 
{
 $res=array_diff($exet[$math[$k]], $exet[$math[$i]]);
 $c1=count($res);
 $c2=count($exet[$math[$k]]);
 if ($c1==$c2) { 
 $group[$k]=$group[$k].",".$math[$i];
 }
}
echo "<br>";
print_r($group[$k]);
echo "<br>";
}
echo "<br>"."............................."."<br>";

?>

<br /><br />
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού  </a>
</body>
</html>