Staggan Posted July 5, 2013 Share Posted July 5, 2013 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 https://forums.phpfreaks.com/topic/279894-display-tournament-bracket/ Share on other sites More sharing options...
_EmilsM Posted July 5, 2013 Share Posted July 5, 2013 foreach within a foreach maybe? Link to comment https://forums.phpfreaks.com/topic/279894-display-tournament-bracket/#findComment-1439534 Share on other sites More sharing options...
JonnoTheDev Posted July 5, 2013 Share Posted July 5, 2013 How would you like it displayed? Link to comment https://forums.phpfreaks.com/topic/279894-display-tournament-bracket/#findComment-1439540 Share on other sites More sharing options...
Staggan Posted July 5, 2013 Author Share Posted July 5, 2013 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 Link to comment https://forums.phpfreaks.com/topic/279894-display-tournament-bracket/#findComment-1439544 Share on other sites More sharing options...
mac_gyver Posted July 5, 2013 Share Posted July 5, 2013 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 https://forums.phpfreaks.com/topic/279894-display-tournament-bracket/#findComment-1439554 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.