Need help with 64 team Tournament Bracket

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dnyce
Forum Newbie
Posts: 1
Joined: Sun Mar 26, 2006 9:47 pm

Need help with 64 team Tournament Bracket

Post by dnyce »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


This is my first time posting here. I have limited PHP experience and need help finishing a script that takes a tournament bracket and updates the database with winning teams in the next tier.  Currently this script works perfectly from tiers (rounds) 1-4. How can I go from 4 to 5 and then 5 to 6? (Semifinals and finals).
The database structure has game ID's from 1-63, and the current code runs with $gameid variables from 0-15 (4 quarters of the draw. This is why rounds 1-4 run fine - b/c games are all within the same quarter. When the winner from quarter 1 needs to play the other winner in the same half of the draw, I can't figure out how to do it. Simply put, winners from gameid 8 (team2) and gameid 53 (team1) need to be placed in gameid61. Winners from gameid 38 (team2) and gameid 23 (team1) need to be placed in gameid63. The winners of those games need to be placed in the last game, gameid 62. Whew! Any takers for this challenge? Here's the code :

Code: Select all

function move_winning_team_up($game_id, $winning_team){
	global $conn;
#	echo '<br>'.$game_id.' is the game id with ';
#	echo $winning_team.' wins<br>';
	
	#Got to modify the insert for different confrences
	if($game_id % 15 == 0){
		$divisor = floor($game_id / 15);
		$divisor = $divisor - 1;
	}else{
		$divisor = floor($game_id / 15);
	}

	$test_value = $game_id - (15 * $divisor);
#	echo $test_value.' is test_value<br>';

	if($test_value % 4 == 1){
		#First tier-swap up
		$next_game = $game_id + 1;
		$sql = "UPDATE bracket SET tmid1='$winning_team' WHERE gid='$next_game'";
#		echo $sql.'<br>';
	}else if($test_value % 4 == 3){
		#First tier-swap down
		$next_game = $game_id - 1;
		$sql = "UPDATE bracket SET tmid2='$winning_team' WHERE gid='$next_game'";
#		echo $sql.'<br>';
	}else if(($test_value <  && ($test_value != 4)){
		#Swap to game 4
		if($test_value == 6){
			#Second tier swap down
			$next_game = $game_id - 2;
			$sql = "UPDATE bracket SET tmid2='$winning_team' WHERE gid='$next_game'";
#			echo $sql.'<br>';
		}else if($test_value == 2){
			#Second tier swap up
			$next_game = $game_id + 2;
			$sql = "UPDATE bracket SET tmid1='$winning_team' WHERE gid='$next_game'";
#			echo $sql.'<br>';
		}
	}else if(($test_value >  && ($test_value != 12)){
		#Swap to game 12
		if($test_value == 14){
			#Second tier swap down
			$next_game = $game_id - 2;
			$sql = "UPDATE bracket SET tmid2='$winning_team' WHERE gid='$next_game'";
#			echo $sql.'<br>';
		}else if($test_value == 10){
			#Second tier swap up
			$next_game = $game_id + 2;
			$sql = "UPDATE bracket SET tmid1='$winning_team' WHERE gid='$next_game'";
#			echo $sql.'<br>';
		}
	}else{
		#Round 3 scenario
		if($test_value == 12){
			#Third tier swap down
			$next_game = $game_id - 4;
			$sql = "UPDATE bracket SET tmid2='$winning_team' WHERE gid='$next_game'";
#			echo $sql.'<br>';
		}else if($test_value == 4){
			#Third tier swap up
			$next_game = $game_id + 4;
			$sql = "UPDATE bracket SET tmid1='$winning_team' WHERE gid='$next_game'";
#			echo $sql.'<br>';

		}

	

	$result = mysql_query($sql, $conn) or die(mysql_error());

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply