We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,140 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

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

5
Contributors
5
Replies
3 Years
Discussion Span
6 Months Ago
Last Updated
6
Views
Sivapatham
Newbie Poster
1 post since Mar 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

darkagn
Nearly a Posting Virtuoso
1,223 posts since Aug 2007
Reputation Points: 404
Solved Threads: 211
Skill Endorsements: 15

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.

davaze
Newbie Poster
1 post since Apr 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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?

Bomf
Newbie Poster
2 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
pritaeas
Posting Prodigy
Moderator
9,293 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,462
Skill Endorsements: 86

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

Bomf
Newbie Poster
2 posts since Nov 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0708 seconds using 2.69MB