0

I am trying to create a tournament table using PHP. This is the HTML code sample.

<table>
    <thead>
        <tr>
            <th>1</th>
            <th>2</th>
            <th>final</th>
            <th>winner</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class="team">team1</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td class="team">team1</td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td class="team">team2</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td class="team">team4</td>
            <td></td>
        </tr>
        <tr>
            <td class="team">team3</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td class="team">team4</td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td class="team">team4</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td class="team">team4 vinner</td>
        </tr>
        <tr>
            <td class="team">team5</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td class="team">team6</td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td class="team">team6</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td class="team">team8</td>
            <td></td>
        </tr>
        <tr>
            <td class="team">team7</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td class="team">team8</td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td class="team">team8</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </tbody>
</table>

I tried creating that table using for loops, but that didn't work very well. Maybe you can give some hints? I am out of ideas.

herzbube
  • 13,158
  • 9
  • 45
  • 87

1 Answers1

0

The elimination system you are working with is called "single elimination" (sometimes "head to head") and the output you wish to achieve is often called "brackets".

Have a look at: Generate a single elimination tournament
and: PHP Single Elimination Tournament Table

This one can be helpful too: Tournament bracket placement algorithm

Community
  • 1
  • 1
LihO
  • 41,190
  • 11
  • 99
  • 167