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 Quote Link to comment Share on other sites More sharing options...
_EmilsM Posted July 5, 2013 Share Posted July 5, 2013 foreach within a foreach maybe? Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted July 5, 2013 Share Posted July 5, 2013 How would you like it displayed? Quote Link to comment Share on other sites More sharing options...
Staggan Posted July 5, 2013 Author Share Posted July 5, 2013 (edited) 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 July 5, 2013 by Staggan Quote Link to comment 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>"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.