New 15-Round Era"; doThing(1, 5); doThing(0, 5); echo "

Old 15-Round Era

"; doThing(1, 0); doThing(0, 0); echo "

9-Round Era

"; doThing(1, 1); doThing(0, 1); function doThing($high, $format) { global $GLOBAL_CONN; global $standardColumns, $stampRequest, $gameLink; $filter = "format=$format AND stage=0"; $runlength = 8; $gameq = $GLOBAL_CONN->query( "SELECT id, maxpoints, broadcastDate FROM cdb_games WHERE $filter ORDER BY broadcastDate" ); $total = 0; $scoreStack = array(); $gameIdStack = array(); $highestTotal = $high ? 0 : 100000; $highestBaseId = -1; while ($game = mysqli_fetch_array($gameq)) { if ($game['maxpoints'] && $game['maxpoints'] > 0) { if (count($scoreStack) == $runlength) { $total -= array_shift($scoreStack); array_shift($gameIdStack); } $gameIdStack[] = $game['broadcastDate']; $scoreStack[] = $game['maxpoints']; $total += $game['maxpoints']; if (count($scoreStack) == $runlength && (($high == 1 && $total > $highestTotal) || ($high == 0 && $total < $highestTotal))) { $highestBaseId = $gameIdStack[0]; $highestTotal = $total; # print $game['broadcastDate'] . " [id=" . $game['id'] . "]: $total (" . join(',',$scoreStack) . ")
"; } } else { $total = 0; $scoreStack = array(); $gameIdStack = array(); } } if ($highestBaseId != -1) { $startGame = grab( "SELECT name2 FROM cdb_games_v WHERE $filter AND broadcastDate = '$highestBaseId'" ); echo "

If " . htmlspecialchars($startGame['name2']) . " had become an octochamp (which he or she may have done), he or she could have made an octochamp total of " . ($high?'':'just ') . " $highestTotal in the following games:

"; showOctoTable("SELECT *, $stampRequest AS broadcastStamp, $gameLink AS points FROM cdb_games_v WHERE $filter AND broadcastDate >= '$highestBaseId' LIMIT $runlength", $standardColumns); } } function showOctoTable($q, $columns) { global $GLOBAL_CONN; $gameQ = $GLOBAL_CONN->query($q); echo "\n"; echo ""; foreach( $columns as $key => $header ){ echo "\n"; } echo ""; while( $game = mysqli_fetch_array( $gameQ ) ){ echo " "; foreach( $columns as $key => $header ){ if ($key === 'points') { $cleanValue = $game[$key]; } else { $cleanValue = htmlspecialchars($game[$key]); } echo ""; } echo "\n"; } echo "
$header
$cleanValue
"; } writeFoot(); ?>