364 Replies to “League Fixtures Generator”

  1. 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. 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.

  3. 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 😉


  4. 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. 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.


  6. @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. 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.


  8. 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. @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. 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. 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. I’d probably have two tables (assuming MySQL):

    CREATE TABLE team (
    name VARCHAR(255)
    ) Engine = InnoDB DEFAULT CHARSET=UTF8;

    CREATE TABLE match (
    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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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

  27. 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. what is the rule for having 1 teams with 6 teams playing out of 3 venues home and away.
    please help.

  29. 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. i have 14 teams in league but have 3 venues with 2 teams each how do i do a fixture list .please

  31. @Sharon –


    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. 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

  33. Hi again i need your help i have 12 teams with with 8 of those teams playing out of 4 venues.
    How do i do it.

  34. Sharon,

    if you go to my online storage bin, at the link given at the end of this reply, then you can download my 12 teams fixture plan. In this fixture pan teams with same letter are never at home in the same round. (For instance A1 is never at home when A2 is at home, B1 is never at home when B2 is at home, and so on.)


  35. Hi Again
    My pool league has gone pear shaped so need to do another fixture list 12 teams 3 venues have 2 teams each.
    we only need to play once each

  36. Sharon,
    if I understand your problem correctly you can stilll use my fixture plan for 12 teams. Teams A1 and A2 are never at home at the same time. The same is true for B1 and B2, for C1 and C2, and so on.

  37. Hi
    I cant seem to get on to the link
    12 teams 3 venues have 2 teams each only need to now play one game each
    Help please

  38. Sharon,

    if you copy the link and paste it into the site address field (where you now see the bluebones.net address), and then click Enter, you should be taken to the storage bin. I’ve just tried it and it works.

  39. Thanks for sharing, it look great.
    However, if I understand correctly this code (I’m not familiar exactly with the programming language) will always generate the same fixture each time.
    It would be great to have there random options.

    So if you have game that user can play several seasons- then first season have 1 fixture, and next season will have different one.

  40. Liron,
    if you send me the names of your teams, and inform me about teams which cannot ply at home in the same league round, then I will send you 10 seasons of fundamentalley different league fixtures.
    You can write to fixtures [at] runbox.no

  41. Great code Fixtureman, I’ve used this alot. But I have an issue, which I don’t believe you’ve considered. When picking complimentary teams i.e Sumteam ‘A’ and Sumteam ‘B’ this works as expected when using the relevant complimentary. A problem exists when I’d like these two teams to play each other on the first game of the new season (and first game of reverse fixture). This is to stop any ‘match fixing’ if they are to play on the last game of the season. I’m not sure how your code could be modified to fix this, but an example I found (which works) can been seen here : hxxp://www.redsealsw.com/8-teams%28819707%29.htm

  42. Wayne, if I understand you correctly, week 8 would be identical to week 1, but on opposite venues. With the fixture plan you presented this means that team 5 gets 3 home games in a row, and (worse!) team 2 gets 3 away games in a row.

  43. Yes, that’s correct. Ideally, i’d like to do home/away/home/away etc. But with the teams from the same club playing each other as early as possible (ideally first game of the new season and first game of the turn-around). The example I found, does this quite successfully, but I prefer your .php file approach. Thanks

  44. Wayne, I think you’ve misunderstood. I’m not the man behind the fixture generator. In fact I don’t know anything about programming. It’s Thomas, the moderator of this site you want. I’m just a semi-regular visitor to this site, one who sometimes is able to help people with fixture problems that Thomas’ generator cannot solve.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.