$teams = array(); foreach ($result as $r) { array_push($teams, $r['team_id']); } function InsertMatch($week, $team1, $team2) { $league_id = $_POST['lid']; $conn = sql_domain(); $stmt = $conn->prepare('insert into matches_round_robin(league_id,week_id,team_1,team_2)VALUES(:l,:w,:t1,:t2)'); $stmt->bindParam(':l', $league_id); $stmt->bindParam(':w', $week); $stmt->bindParam(':t1', $team1); $stmt->bindParam(':t2', $team2); $stmt->execute(); } $schedule = roundRobin($teams); // Week = 1 $week = 1; foreach ($schedule as $sch) { foreach ($sch as $s) { InsertMatch($week, $s['Home'], $s['Away']); } $week++; } function roundRobin(array $teams) { if (count($teams) % 2 != 0) { array_push($teams, "bye"); } $away = array_splice($teams, count($teams) / 2); $home = $teams;
array_unshift($equipos, array_pop($equipos)); array_unshift($equipos, $equipoBase); } foreach ($liga as $jornada) { $jornadaVuelta = []; foreach ($jornada as $partido) { $partidoVuelta['local'] = $partido['visitante']; $partidoVuelta['visitante'] = $partido['local']; $jornadaVuelta[] = $partidoVuelta; } array_push($liga, $jornadaVuelta); } return $liga; } $equipos = array('Real Madrid', 'Barcelona FC', 'Sporting Gijon', 'Rayo Vallecano', 'Getafe', 'Sevilla'); $calendarioLiga = roundRobin($equipos); ?> <table> <?php foreach ($calendarioLiga as $numJornada => $jornada) { echo '<table>'; echo '<th>'; echo "Jornada " . ($numJornada + 1); echo '</th>'; foreach ($jornada as $partido) { echo '<tr>'; echo '<td>'; echo $partido['local']; echo '</td>';
$sql = "SELECT * FROM `Tournaments` WHERE tournId=" . $id; $q = mysqli_query($db_conx, $sql); $tourn_string = mysqli_fetch_array($q); $teams_in = $tourn_string["teamsIn"]; //Niz ekipa $sql = "SELECT * FROM `Teams` WHERE teamID IN ({$teams_in}) ORDER BY teamID"; $q = mysqli_query($db_conx, $sql); $br = 0; while ($row = mysqli_fetch_array($q)) { $members[$br] = $row["teamName"]; $br++; } if (count($members) == $tourn_string["maxTeams"]) { //Još jedna provjera //Napravi runde $rounds = roundRobin($members); //Kreiraj tablicu rezultata u bazi $table_name = "Results_" . $id; $sql = "CREATE TABLE " . $table_name . "\n\t\t(\n\t\tgame int UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n\t\tround int UNSIGNED,\n\t\tteam1 varchar(255) COLLATE latin2_croatian_ci,\n\t\tteam2 varchar(255) COLLATE latin2_croatian_ci,\n\t\tres1 varchar(255) COLLATE latin2_croatian_ci,\n\t\tres2 varchar(255) COLLATE latin2_croatian_ci\n\t\t) ENGINE = INNODB"; if (!mysqli_query($db_conx, $sql)) { echo "1"; exit; } else { //Dodaj ime tablice u zapis turnira $sql = "UPDATE `Tournaments` SET resultsTable='{$table_name}', started='1' WHERE tournId='{$id}' LIMIT 1"; if (!mysqli_query($db_conx, $sql)) { echo "2"; exit; } else { //Ispuni je poljima iz roundRobin-a foreach ($rounds as $round => $games) {