Jump to content

Creating league fixtures


Madatan

Recommended Posts

I have been pondering upon this matter but I just cant figure out a good solution. I would like to recieve some good ideas and help on how to create a pretty simple league fixture code.

 

So lets say I got

 

X vs Y

G vs H

A vs B

 

and I want every team to meet every team 3 times. How should I code to do that automatically and random? Then I want the fixtures inserted into a database table.

 

Any suggestions?

Link to comment
Share on other sites

ok i've been messing around with the code for about 10 mins and I think it's what you want ;D

 

<?php
error_reporting(E_ALL);
$teams1 = array("x","y","g","h","a","b");
$teams2 = $teams1;
$i = 0;
foreach($teams1 as $team1)
{
foreach($teams2 as $team2)
{
	if((array_keys($teams2, $team2)) > (array_keys($teams1, $team1)))
	{
		$matches[$i] = "{$team1} Vs {$team2}";
		$i++;
	}
}
}
for($j = 0; $j <= 2; $j++)
{
shuffle($matches);
$k = $j+1;
echo "<b>Week {$k}</b><br />";
foreach($matches as $match)
{
	echo "{$match} <br />";
}
}
?>

 

Well I hope that helps, it's not the prettiest code ever, but hopefully it does the job :D

 

~ Chocopi

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.