I’ve made my fixture generating code available via a web page for those who don’t want to delve into programming in order to generate a fixture list.

Fixtures Generator (now in PHP as I didn’t want to have to install Tomcat again). Source code.

Skip to content
# League Fixtures Generator

##
364 Replies to “League Fixtures Generator”

### Leave a Reply

Adventures in Computer Programming – bakert@gmail.com

I’ve made my fixture generating code available via a web page for those who don’t want to delve into programming in order to generate a fixture list.

Fixtures Generator (now in PHP as I didn’t want to have to install Tomcat again). Source code.

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

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

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

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

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.

@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?

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!

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…

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

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?

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.

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.

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.

I would look into replacing this line:

with something like:

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

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

Try

`print_r`

on your array – that will show you the structure of it.is it possible to have a league with 5 teams to only play 3games

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.

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

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.

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

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.

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

Is VB.net Version available

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

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

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.

Its a little bit of a problem is that the only way possible.

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.

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

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.

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

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?

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

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

Thankyou

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

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

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.) http://www.4shared.com/dir/19186095/a6abdda2/sharing.html#dir=1dHAqz0t

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 thanks sharon

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.

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 Sharon

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.

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.

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

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

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.

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

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.

Doh! sorry Fixtureman, my misunderstanding.