Jump to content

Display Tournament Bracket


Staggan

Recommended Posts

Hello

 

I am looking for some help to display an array which contains the data for our tournament.... I have been using a class called class_knockout.php which has proved a huge help... but it uses GDLIB to display the results and I am getting varying results from different browsers and often getting garbage instead... even though the array is always valid.

 

Here is how the array looks:

 

 

Array
(
    [1] => Array
        (
            [0] => Array
                (
                    [c1] => WARS
                    [s1] => 2
                    [c2] => Bueca Juerniores
                    [s2] => 1
                )

            [1] => Array
                (
                    [c1] => BUECA JUENIORESITA
                    [s1] => 0
                    [c2] => FC Naulakone
                    [s2] => 1
                )

            [2] => Array
                (
                    [c1] => pesfi
                    [s1] => 0
                    [c2] => FenderZ
                    [s2] => 1
                )

            [3] => Array
                (
                    [c1] => HITers
                    [s1] => 0
                    [c2] => Almargem FC
                    [s2] => 1
                )

        )

    [2] => Array
        (
            [0] => Array
                (
                    [c1] => WARS
                    [s1] => 0
                    [c2] => FC Naulakone
                    [s2] => 1
                )

            [1] => Array
                (
                    [c1] => FenderZ
                    [s1] => 0
                    [c2] => Almargem FC
                    [s2] => 1
                )

        )

    [3] => Array
        (
            [0] => Array
                (
                    [c1] => FC Naulakone
                    [s1] => 0
                    [c2] => Almargem FC
                    [s2] => 1
                )

        )

)

 

 

 

The outer array is the round, 1 being the first and 3 being the final, the inner array is each game in that round with each game having 2 competitors, c1 and c2, and 2 scores, s1 and s2

 

The number of rounds can be dynamic as well.. so there could be up to maybe 32 games in a single....

 

Any advice would be appreciated

 

Thanks

 

 

 

 

Link to comment
Share on other sites

Ideally like a normal tournament bracket...

Round 1 games in column1, round 2 in column 2 etc.....

 

Like this....

 

TEAM 1   2

                         TEAM 2 

TEAM 2   3

 

 

 

Thanks

Edited by Staggan
Link to comment
Share on other sites

assuming your array of data is in $data, a solution using a table rowspan attribute and a little math/array indexing -

$rowspan = 1;
$output = array(); // where to build the output at
$heading = '';
foreach($data as $round=>$arr){
    $heading .= "<th>Round $round</th>"; // make some headings for each round
    if($round !=1){ // do only after the first round
        $rowspan *= 2; // double the rowspan - 1,2,4,8,
    }
    foreach($arr as $key=>$value){ // loop over all the data within each round
        $index = $key * $rowspan; // line number to add the output at
        if(!isset($output[$index])){$output[$index] = '<tr>';} // start each line
        $output[$index] .= "<td rowspan='$rowspan'>{$value['c1']} - {$value['s1']}<br>{$value['c2']} - {$value['s2']}</td>";
    }
}

// display the result
echo "<table border='1'>\n"; // no css for example purposes only
echo "<tr>$heading</tr>\n"; // the heading row
echo implode("</tr>\n",$output); // terminate each line and implode into a string
echo "</tr>\n"; // terminate last line
echo "</table>";
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.