function mergeTeams($tournament_id) { global $conn; // 1. Identify top 10 players based on performance score in the local tournament $sql = "SELECT player_id, team_id, score FROM tournament_stats WHERE tournament_id = '$tournament_id' ORDER BY score DESC LIMIT 10"; $top_players = $conn->query($sql); // 2. Create the "Elite Team" for Indoevano $conn->query("INSERT INTO sports_teams (team_name, is_merged) VALUES ('Indoevano Elite Alpha', 1)"); $new_team_id = $conn->insert_id; // 3. Re-assign top players to the Elite Team while($player = $top_players->fetch_assoc()) { $p_id = $player['player_id']; $conn->query("UPDATE players SET elite_team_id = '$new_team_id' WHERE id = '$p_id'"); } return "Indoevano Elite Team has been formed successfully!"; }