karimali831 Posted July 29, 2012 Share Posted July 29, 2012 Hi all, I am trying to construct a HTML table for the loser bracket for a tournament-tree, the upper-bracket table structure is more straight forward but I am having difficulty in constructing the lower/loser bracket. This is what I have so far:- This is what I am looking for with the lower bracket, this is the structure I need:- Anyone can help me on this please? The code for the lowerbracket section is under //////////////////////////////// LOWER BRACKET //////////////////////////////// This is the full code:- <?php if(isset($_GET['action'])) $action = $_GET['action']; else $action=''; $tourney[id] = 11; $tinfo=safe_query("SELECT * FROM tourneys WHERE tid='$tourney[id]'"); $tinfo=mysql_fetch_array($tinfo); switch($action){ case "brackets": tourney_brackets(); break; } function tourney_brackets(){ global $tinfo, $url, $out, $plyr, $site, $uinfo, $misc, $file; $brackets=safe_query("SELECT bid,pid,name FROM brackets2 WHERE tid='$tinfo[tid]' ORDER BY bid"); while(list($bid,$pid,$name)=mysql_fetch_row($brackets)){ if($pid){ $bracket[$bid]="<font type='arial' size='2'><a href='$url[base]/$file[teams]?teamid=$pid'>$name</a></font>"; }else{ $bracket[$bid]="$name"; } $pid=""; } $tinfo[size] = 16; $brackets="$tinfo[size]"; $spots=($brackets * 2 - 1); $temp_rows="$brackets"; while($temp_rows > 1){ $rowcount++; if($rowcount > 1){ $temp_rows=($temp_rows / 2); } $listrows.="-> $temp_rows"; $rows="$rowcount"; } $rowwidths=round(100 / $rows - 0.5); $actualrows=($rows * 2); //////////////////////////////// UPPER BRACKET //////////////////////////////// $out[body]=$out[body]." <center> $bannerhead $out[banner] $bannerfoot <br> $tablehead <strong> <table width='100%' cellspacing='$cellspacing' cellpadding='$cellpadding' bgcolor='$border'> <tr class ='altcolor'> <td width='100%' valign='top' align='center'> <b>$tinfo[name] Brackets</b><br> </td></tr></table> <br><br> <table width='100%' cellspacing='$cellspacing' cellpadding='$cellpadding' bgcolor='$border'> <tr> "; $counter="$brackets"; while($counter > 1){ if($round){ $counter=($counter / 2); } $lastcb="$countbrackets"; $countbrackets=""; $game=""; $round++; $finals=($rows - 1); $winner=($rows); $roundgamesay="Round $round Games"; if($round=="$winner"){ $roundgamesay="Winner!"; } if($round=="$finals"){ $roundgamesay="Finals"; } $out[body]=$out[body]." <td align='center' valign='center' width='$rowwidths%' colspan='1' style='border-collapse:collapse; padding: 0px;'><b>$roundgamesay2</b><br> <table width='100%' cellspacing='$cellspacing' cellpadding='$cellpadding' bgcolor='$border' style='border-collapse:collapse; padding: 0px;'> "; $spacesetcount=""; while($countbrackets < $counter){ $countbrackets++; $spot++; $spacesetcount++; if($spacesetcount=="4"){ $spacesetcount=""; } $bracketid="$round"."_"."$countbrackets"; $out[body]=$out[body]." <tr> <td align='left' valign='center' width='100%' bgcolor='#e4f3ff'>$bracket[$bracketid] $spot</td> <td align='left' ".($round!=$winner ? "style='border-right:2px solid #333333;'" : "")." bgcolor='#D9D9D9' valign='center' width='100%'> </td> </tr> "; if($countbrackets < $counter){ $spacecounter++; $spacecounter=($spacecounter + 1); if($spacecounter==2){ $roundx2p1=($lastroundx2p1 * 2 + 1); if($round==1){ $roundx2p1="1"; } while($countspaces < $roundx2p1){ $countspaces++; $spacecentercount++; $spacecenterword=""; $alignspacer1="left"; $spacecentercountcheck=($lastroundx2p1 + 1); if($spacecentercount=="$spacecentercountcheck"){ $spacecenterwordcount++; if(($spacecenterwordcount==1)||($spacecenterwordcount==3)){ $actualgamecount++; $detail = $spot / 2 + 0.5; $spacecenterword="<b>Game $actualgamecount2 $detail</b>"; $alignspacer1="center"; if($spacecenterwordcount==3){ $spacecenterwordcount=""; $spacecenterwordcount++; } } } $out[body]=$out[body]." <tr> <td align='$alignspacer1' valign='center'> $spacecenterword</td> <td align='left' valign='center' ".(is_odd($spot) ? "style='border-right:2px solid #333333;'" : "")."> </td> </tr> "; } $spacecounter=""; $countspaces=""; $spacecentercount=""; } } } $spacecenterwordcount=""; $actualgamecount=""; $lastroundx2p1="$roundx2p1"; $out[body]=$out[body]." </table> </td> "; } ///////////// unset($spot); unset($round); $spot = $tinfo[size] * 2 + 1; $brackets = $tinfo[size] / 2; //////////////////////////////// LOWER BRACKET //////////////////////////////// $out[body]=$out[body]." <center> $bannerhead $out[banner] $bannerfoot <br> $tablehead <strong> <table width='100%' cellspacing='$cellspacing' cellpadding='$cellpadding' bgcolor='$border'> <tr class ='altcolor'> <td width='100%' valign='top' align='center'> <b>$tinfo[name] Brackets</b><br> </td></tr></table> <br><br> <table width='100%' cellspacing='$cellspacing' cellpadding='$cellpadding' bgcolor='$border'> <tr> "; $counter="$brackets"; while($counter > 1){ if($round){ $counter=($counter / 2); } $realround = $round + 1; $lastcb="$countbrackets"; $countbrackets=""; $game=""; $round++; $finals=($rows - 1); $winner=($rows); $roundgamesay="Round $round Games"; if($round=="$winner"){ $roundgamesay="Winner!"; } if($round=="$finals"){ $roundgamesay="Finals"; } $out[body]=$out[body]." <td align='center' valign='center' width='$rowwidths%' colspan='1' style='border-collapse:collapse; padding: 0px;'><b>$roundgamesay</b><br> <table width='100%' cellspacing='$cellspacing' cellpadding='$cellpadding' bgcolor='$border' style='border-collapse:collapse; padding: 0px;'> "; $spacesetcount=""; while($countbrackets < $counter){ $countbrackets++; $spot++; $spacesetcount++; if($spacesetcount=="4"){ $spacesetcount=""; } $bracketid="$round"."_"."$countbrackets"; $out[body]=$out[body]." <tr> <td align='left' valign='center' width='100%' bgcolor='#e4f3ff'>$bracket[$bracketid] $spot </td> <td align='left' ".($round!=$winner ? "style='border-right:2px solid #333333;'" : "")." bgcolor='#D9D9D9' valign='center' width='100%'> </td> </tr> "; if($countbrackets < $counter){ $spacecounter++; $spacecounter=($spacecounter + 1); if($spacecounter==2){ $roundx2p1=($lastroundx2p1 * 2 + 1); if($round==1){ $roundx2p1="1"; } while($countspaces < $roundx2p1){ $countspaces++; $spacecentercount++; $spacecenterword=""; $alignspacer1="left"; $spacecentercountcheck=($lastroundx2p1 + 1); if($spacecentercount=="$spacecentercountcheck" || $round==1){ $spacecenterwordcount++; if(($spacecenterwordcount==1)||($spacecenterwordcount==3)){ $actualgamecount++; $detail = $spot / 2; $spacecenterword="<b>Game $actualgamecount2 $detail</b>"; $alignspacer1="center"; if($spacecenterwordcount==3){ $spacecenterwordcount=""; $spacecenterwordcount++; } } } $out[body]=$out[body]." <tr> <td align='$alignspacer1' valign='center'> $spacecenterword</td> <td align='left' valign='center' ".(!is_odd($spot) ? "style='border-right:2px solid #333333;'" : "")."> </td> </tr> "; } $spacecounter=""; $countspaces=""; $spacecentercount=""; } } } $spacecenterwordcount=""; $actualgamecount=""; $lastroundx2p1="$roundx2p1"; $out[body]=$out[body]." </table> </td> "; } ////////////////// $out[body]=$out[body]." </tr> </table><br><br> <table width='100%' cellspacing='$cellspacing' cellpadding='$cellpadding' bgcolor='$border'> <tr class ='altcolor'> <td width='100%' valign='top' align='center'> <br> </td></tr></table> <br> $tablefoot"; echo $out[body]; } ?> Thanks to all Quote Link to comment https://forums.phpfreaks.com/topic/266417-help-to-do-the-loserbracket/ 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.