SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help w/ Tournament Brackets?

    Hello, everyone. I'm an avid Counter-strike fan and my clan has asked me to set-up an inhouse tournament. Well, I figured, I might as well make a general tournament bracket so that if we ever decide to have a tournament in the future, we can just use the same script to set it up.

    You can check out the basic look of the brackets here:
    http://cspokemon.speechrocks.com/brackets.html

    (Yes, my clan is [Pokemon]... no... no, I don't like Pokemon)

    Now, I realized the immense problem in setting this up when I tried to design my MySQL table for it...

    What I ended up doing was using 5 columns in the table: team_name, 1rnd, 2rnd, 3rnd, 4rnd. The 4rnd column would merely be there to designate the winner of the tournament. Now, the 1rnd column cannot be null, but the 2rnd, 3rnd, and 4rnd can be, seeing as it's a single elimination tourney. These columns get filled in according to what match they're in. For example, the first tier of the tournament has 4 different matches. Those matches are designated A-D. Since they are in the first round, I designated that by adding a "1" suffix. So now, each match is 1A-1D. However, to designate the team itself, I added either a 1 or a 2 at the end (since each match consists of 2 teams). For example, under the first column, 1A1 and 1A2 are going against each other, as is 1B1 and 1B2, etc.

    Now, in setting up the viewing script (so that people can see the brackets with the actual team names in them), I realized that I would have to make a query to determine each spot on the brackets. For example, to determine who would be in the first match, I would have to run a query finding one competitor and then another query to find the opponent. This is entirely impractical (and difficult to explain to you). Basically, what I'm looking for is someway to select all the information from the table in one query and then use PHP to write in where they belong.

    For example, instead of saying...

    PHP Code:
    $query mysql_query("SELECT team FROM tourney WHERE 1rnd = 1A1");
    ...
    $query mysql_query("SELECT team FROM tourney WHERE 1rnd = 1A2");
    ...
    etc

    I would rather go like this...

    PHP Code:
    $query mysql_query("SELECT * FROM tourney"); 
    And then have PHP sort the results by the 1rnd, 2rnd, 3rnd, and 4rnd values. It's quite confusing, but I hope someone here can understand.

    -Mike

  2. #2
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there, I'd be pretty interested if you get somethng worked out & get a bracket system working. I gave up for the time being on mine, It was pretty complex for me since i've never done ANY programming before.

    I too wanted to know the same thing & I got this piece of code in a response. Basically you query the db only once Then once it's in an array you just loop through that with a foreach statement. I'm assuming that's what you mean, you want to cut down on the calls to the db.

    Here's the snippet I got.
    PHP Code:
    $result mysql_query("SELECT * FROM tourney");
    if (!
    $result) { echo("<P>Error performing query for Tourney results: " mysql_error() . "</P>");
     exit();}

    // Loop through and gather the data in the result set once! 
    // Assign each $rowresult to the array $rows 
    while ( $rowresult mysql_fetch_array($result) ) 

    $rows[] = $rowresult

    // each time you want process the results 
    // just loop through each row of the array $rows 
    // (which is now storing all the resultset data) 
    // using foreach. 
    Then call it when you need it like this
    PHP Code:
    foreach ($rows AS $rowresult

    //Do this
    }
    reset($rows); 
    Hope that helps.
    Last edited by whofarted; Mar 17, 2002 at 11:46.
    You smell something?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •