<?php
include ('logue.php'); 
include ('entete2.php');
include ('entete.php');

$nbre_changés = 0;
$req = "SELECT id, Count( * ) , galaxi, system, position
FROM `matgraph_users`
WHERE 1
GROUP BY galaxi, system, position
HAVING Count( id ) > 1";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 ) {
  While ( $row = mysql_fetch_array($res) ) {
  	UNSET($i);
  	UNSET($fait);
  	for ($i = 1; $i <= 10; $i++) {
  		$sql2 = "SELECT id FROM `matgraph_users` WHERE galaxi=$row[galaxi] AND system=$row[system] AND position=$i";
			$res2 = mysql_query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
			$num2 = mysql_num_rows($res2);
			if ($num2 == "0" && $fait != "OUI") {
				$requete = "UPDATE matgraph_users SET position=$i WHERE id='$row[id]'";
				$action = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error()); 
				$nbre_changés++;
				$fait = "OUI";
			}
		}
	}
}

echo"<br><br><div align=\"center\">Coordonnées changées : $nbre_changés changés sur $num </div>";

?>


