287 thoughts on “League Fixtures Generator

  1. Michael

    Hello Sir, Need your thoughts on way to plan a 1/4s and 1/2s (quarters & semi ) for teams in 2 pools say A and B each having 8 teams each and the progression to semis and finals ..Pairings and home and away games i will really appreciate . Happy new year

  2. James

    Hi I am having trouble with my fixtures as some teams in our league have more than one team so the cant play at home or away at the same time?] can you help. thanks james

  3. Steve

    Hi, Been looking everywhere for one of these that caters for complementary teams as its needed for our cricket club – is there a version of the code including this ‘fix’ available anywhere. Dont know php or java, but I guess I can figure out the logic ;) Steve

  4. bakert Post author

    The existing generator pairs up teams so that they don’t play at home at the same time. If you have (for example) 8 teams the following pairs will never play at home at the same time: 1&5, 2&6, 3&7, 4&8. This works for any number of teams. The pairs are team N and team N + (total number of teams / 2 rounded up).

  5. Ade

    Hi, Is it possible to send the teams from a database rather than from the form? I am doing this but the output is just Array V Array all the way through… Any help is appreciated. Thanks.

  6. bakert Post author

    @Ade – sounds like the problem is in your code that is fetching the teams from the db rather than with the fixtures code. “Array” is the default string representation of an array in PHP so perhaps you need something like $array['team_name'] in your code where you currently have $array?

  7. Ade

    Hi, I have been able to resolve the issue similar to how you’ve suggested. I ran a query and stored the results of that query in a new array passing in the team name each time on each iteration. Thanks!

  8. Ade

    I am trying to find a way to prevent certain teams playing at home on the same day. I have seen @bakert response at how for 8 teams certain pairings never play at home at the same time, but one of the divisions in my league has 10 teams.. I can’t seem to find a pairing that never occurs…

  9. bakert Post author

    @Ade the pairings that never play at home at the same time change based on the number of teams. For 10 it’s 1&6, 2&7, 3&8, 4&9, 5&10. It’s always x & x + (n/2) where X is the number of a team and n is the total number of teams.

  10. Ade

    Thanks for that I understand now. That is spot on. Just out of interest, have you come across the best way to store the two teams into two different columns in the database?

  11. Ade

    Currently I have the array index numbers storing in the database, but I wish to store the team names instead of the array index numbers. All help is appreciated.

  12. bakert Post author

    I’d probably have two tables (assuming MySQL): CREATE TABLE team ( id INT PRIMARY KEY AUTO_INCREMENT UNIQUE NOT NULL, name VARCHAR(255) ) Engine = InnoDB DEFAULT CHARSET=UTF8; CREATE TABLE match ( id INT PRIMARY KEY AUTO_INCREMENT UNIQUE NOT NULL, date DATETIME NOT NULL, home_id INT NOT NULL, away_id INT NOT NULL, home_score INT, away_score INT, FOREIGN KEY (home_team_id) REFERENCES team (id), FOREIGN KEY (away_team_id) REFERENCES team (id) ) Engine = InnoDB DEFAULT CHARSET=UTF8; For each team make a row in the database: INSERT INTO team (name) VALUES (‘Everton’), (‘Liverpool’), (‘Manchester United’), … ; For each fixture make a row in the database: INSERT INTO match (date, home_id, away_id) VALUES (’2013-04-01 15:00′, 1, 2), (’2013-04-01 15:00′, 3, 4), …; Then when you want to see the dates and teams in all the fixtures: SELECT m.date, th.name AS team_home, ta.name AS team_away FROM match AS m INNER JOIN team AS th ON m.home_id = th.id INNER JOIN team AS ta ON m.away_id = ta.id; There are lots of other ways to go about it, of course, but this is a reasonable approach IMHO.

  13. Ade

    Thanks for your help, it is very much appreciated. That is something that I already have. I don’t think I explained what I was doing properly! I am trying to get my head around how I can transfer the output of this generator into a database. Currently the array index number is getting inserted into the database, not the team names.. I am already extracting the team names from the database into an array that is being used for the fixtures. The fixtures output on the screen with the team names, but I can’t find a way to insert them into my fixtures table by manipulating the code on here. I seem to get stuck at that point and no matter what I try I can’t seem to manage it. Thanks again.

  14. bakert Post author

    I would look into replacing this line:

      $rounds[$round][$match] = team_name($home + 1, $names)       . " v " . team_name($away + 1, $names);  

    with something like:

      $rounds[$round][$match] = array('home_id' => $arrayOfTeamIds[$home], 'away_id' => $arrayOfTeamIds[$away]);  

    Then at the end of the process you have a data structure you can traverse to generate your SQL. I would also not bother with team names but instead have ids as the input. So get the ids out of the database not the names. Then you can do something like

      foreach ($rounds as $round) {      foreach ($round as $match) {          $sql = "INSERT INTO match (home_id, away_id, date) VALUES (?, ?, ?)";          runSqlAgainstDatabaseHoweverYouAreDoingThat($sql, [$match['home_id'], $match['away_id']);      }  }  
  15. Ade

    Thanks for the help. I don’t know where this would fit into the code, furthermore I don’t know how to extract the actual team IDs from the loops as they get stored in the array so where we need to pass the values for the sql query I can’t get my head around what to pass into it.. I thought there’d have been somewhere on the internet that had done this before particularly with this code given how popular it is but I have found nothing, it is bizarre..

  16. Fixtureman

    Anonymous, you have probably figured it out by now, but anyhow the answer is NO. One cannot have a 5-team league with each team playing 3 matches. To realize this: Imagine the final league table for your league. If all 5 teams play 3 matches the sum of the “Played” column would be 15. But this sum cannot be an odd number. If A and B are two of the teams in your league, then an AvB match would count as one played game in both A’s and B’s number of played matches. The sum of the “Played” column is therefore always an even number.

  17. Paul Clark

    I started the season with 19 teams and one dropped out. We are at the half way point of the season (which usually just means a reversal of all first half fixtures) and I would like to revert to an 18 team grid but I am finding it impossible to reconcile the 20 team grid with the 18 team grid. I have 4 venues with two teams which is complicating the situation. It will mean 2 teams with byes each week if I cant solve it, which is less than ideal. Any help would be useful.Cheers

  18. Fixtureman

    Paul, I doubt if this is a solveable problem. As I understand it your goal is to let the 18 remaining teams play the second half of the season in 17 rounds, so that 1) teams sharing stadium are not at home in the same round, and 2) teams are to play each other on opposite venue compared to the first half of the season. (That is: If A played at home versus B in the first half of the season, then B should play at home gainst A in the second half of the season.) It’s condition No 2 that makes this an extremely difficult problem. The only possible way to solve it would be to take an 18-team fixture plan and chose teams in a way that would satisfy condition 2 (without violating condition 1). And frankly, even without condition 1 to consider I doubt if it’s possible. My advice to you is to play the second half of the season with your original fixtures, even if it will result in two teams with bye in each round.

  19. Rod

    Have been running pool leagues for many years. leagues have consisted of 8.10 or 12 teams but need a formula for 14 teams

  20. Fixtureman

    Rod, if you click on my username you’ll be taken to an online storage bin with many fixture plans. One of them is called “14 teams”- That should solve your problem. In this 14-team plan teams with the same capital letter (for instance A1 and A2) are never at home in the same round.

  21. bakert Post author

    You can also use the Fixtures Generator linked above http://bluebones.net/fixtures.php which will give you this: http://bluebones.net/fixtures.php?teams=14

  22. bakert Post author

    No VB.NET version but I imagine converting the Java or PHP version wouldn’t be very hard. The algorithm is not that complicated.

  23. Geoff

    planning a golf tournament 16 players over 9 games each game has 4 players in group so 4 groups of 4 is there away so every player plays with each other at least once in the 9 games

  24. Fixtureman

    Geoff, if you group your players into 8 teams, with 2 players in each team, and then apply the fixture generator for an 8-team league. You can use the first 9 rounds from this fixture generator. This way every player will play with every other player at least once during the 9 games (rounds). However, each player will have one other player with whom he’s always playing, but you said nothing to indicate that this would be a problem.

  25. Fixtureman

    Geoff, after round 7 (game 7) all players have played with everybody else once (except the one they are in a team with, whom they’ve played with twice. For the last two rounds (games) you can group them as you like. So they don’t have to play with their fixed partner in rounds 8 and 9, if that helps.

  26. janet

    I can you advise me how to do a fixture list for 8 team’s but 3 of the team’s have an a and a b teams, every time I try it it’s is giving me results of a and b team are playing at home at the same time rather than one home and one away. man thanks janet

  27. bakert Post author

    For an 8 team event the fixtures list is: http://bluebones.net/fixtures.php?teams=8 The complimentary teams are 1 and 5, 2 and 6, 3 and 7, 4 and 8.

  28. sharon

    what is the rule for having 1 teams with 6 teams playing out of 3 venues home and away. please help. Thanks

  29. bakert Post author

    I’m not sure I understand your question Sharon. In a 6-team setup teams 1 and 4, 2 and 5, and 3 and 6 are complementary (that is, they never play at home at the same time as each other). Does that help?

  30. sharon

    i have 14 teams in league but have 3 venues with 2 teams each how do i do a fixture list .please Thanks Sharon

  31. bakert Post author

    @Sharon – http://bluebones.net/fixtures.php?teams=14 The complementary teams are 1 and 8, 2 and 9, 3 and 10, 4 and 11, 5 and 12, 6 and 13, and 7 and 14. You can use any of those pairs for the pairs that share venues.

  32. Garry Francis

    Hi I have 4 divisions, Top 3 divisions with 8 teams and I division with 10 teams. Is there a formula that matches them both up as I have venues with Teams in a division of 8 and the division of 10. Can you help

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>