1,105,197 Community Members

How can I generate a round robin tournament in PHP and MySQL?

Member Avatar
Sivapatham
Newbie Poster
1 post since Mar 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I need to generate sequences of games using the round robin algorithm. I have the php page where the user can input the tournament name which will be inserted into the database and it has got a drop down menu up to 32 teams (select number of teams).

So if I select 4 teams in the page, so it will be from team 1 to team 4 which would be 6 matches because every team plays the other team once. I know how the algorithm works but I am not quite sure how to write the query for that.

I created the table team:

Team_id Teams
01 Team 1
02 Team 2
03 Team 3
etc etc

And a bit of php:

var n = teams; //entered teams
var nr = n-1; //Rounds


$result = mysql_query("SELECT teams from team");

while($row = mysql_fetch_array($result))

{

for(i=1; i<n; i++)


print "{$row} <br>";
}

Can anyone help me to do the rotatation of the arrays to create the round robin, please??

Member Avatar
darkagn
Veteran Poster
1,199 posts since Aug 2007
Reputation Points: 279 [?]
Q&As Helped to Solve: 216 [?]
Skill Endorsements: 21 [?]
 
0
 

Hi Sivapatham and welcome to DaniWeb,

A very simple algorithm for this would be:

for( $i = 0; $i < $n; $i++ ) // if $n is number of teams
{
  for( $j = $n-1; $j > $i; $j-- )
  {
    // teams for this match have id's = $i and $j
    // I'll let you work out what you want to do here...
  }
}

I am sure there is a more efficient way of doing this, but this algorithm should work.

davaze
Newbie Poster
1 post since Apr 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

If someone is still looking for a simple round robin php script then leave a note. I just created a new script from scratch that does just that. Send any array of information to my function and it will generate the schedule for you. You can then attach every created round to a date or whatever you want to do with it.

Member Avatar
Bomf
Newbie Poster
2 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I need a script like this. A MySQL that have got the teams. Then a script should make a trounament tree. Can someone help me?

Member Avatar
pritaeas
mod_pritaeas
11,285 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,831 [?]
Skill Endorsements: 154 [?]
Moderator
Featured
Sponsor
 
0
 
Member Avatar
Bomf
Newbie Poster
2 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Ok, sry. I need a Single Elimination PHP + MYSQL Script. No Round Robin.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article