<?	
$req = "SELECT * FROM matgraph_constructionvaisseaux WHERE findeconstruction < ".time()." AND proprietaire='$planete' "; 
$res = db_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) ) {
  
	$req3 = "SELECT nbre FROM matgraph_nbrevaisseaux WHERE vaisseau = $row[nom] AND planete='$planete'";
	$res3 = db_mysql_Query($req3)or die('erreur sql<br>'.$req3.'<br>'.mysql_error());
	$row3 = mysql_fetch_array($res3); 
	
			$sql2 = "SELECT fer, orr, ada, ura FROM matgraph_vaisseaux WHERE id = '$row[nom]'" ;
			$res2 = db_mysql_Query($sql2) or die('Erreur SQL! <br>' . $sql2 . '<br>' . mysql_error()) ;
			$row2 = mysql_fetch_array($res2) ;
			
			$Score_vaisseau += ( $row2['fer'] + $row2['orr'] + $row2['ada'] + $row2['ura'] );
	
	$new_nombre = $row3[nbre] + 1 ;
	
	$sql3 = "UPDATE matgraph_nbrevaisseaux SET nbre='$new_nombre' WHERE vaisseau = $row[nom] AND planete='$planete'";
	$res3 = db_mysql_Query($sql3)or die('erreur sql<br>'.$sql3.'<br>'.mysql_error());
	$sql4 = "DELETE FROM matgraph_constructionvaisseaux WHERE id = $row[id]";
	$res4 = db_mysql_Query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
	}
}
//Maj pts
	$req2 = "SELECT pts_flotte FROM matgraph_users WHERE id = '$idlogin'";
	$res2 = db_mysql_Query($req2)or die('erreur sql<br>'.$req2.'<br>'.mysql_error());
	$row2 = mysql_fetch_array($res2); 
	
	$Score_vaisseau += $row2[pts_flotte];
	
	$req_UPDATE = "UPDATE matgraph_users SET pts_flotte = '$Score_vaisseau' WHERE id = '$idlogin'" ;
	$maj=db_mysql_Query($req_UPDATE) or die('Erreur SQL! <br>' . $req_UPDATE . '<br>' . mysql_error()) ;
?>