chriscloyd Posted November 11, 2008 Share Posted November 11, 2008 this is what the script needs to do their is 10 teams take a team and match them up with another team it checks previous matches and see if it was previsouly matched up with that team if not make a match in the match table? if confused ask questions please need help Quote Link to comment Share on other sites More sharing options...
premiso Posted November 11, 2008 Share Posted November 11, 2008 Do you have any code started? If not I think you should post in the freelance section, no one on this form wants to write a whole script for a user for free who is not even trying himself. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted November 11, 2008 Author Share Posted November 11, 2008 no im trying ill show u my code <?php $get_allteams = mysql_query("SELECT * FROM teams WHERE game = 'css' AND division = 'a'"); $num_teams = mysql_num_rows($get_allteams); $max_teams = $num_teams; $min_teams = 1; while ($teams = mysql_fetch_assoc($get_allteams)) { $get_home_team = rand($min_teams,$max_teams); $get_away_team = rand($min_teams,$max_teams); } ?> but thats all i got i dont know what to do if they are the same and how to go back and choose a new number or to check if they have already been matched up previous matches or if they have already been matched up to a dif team this week Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted November 11, 2008 Author Share Posted November 11, 2008 i have been trying for weeks and nothing seems to work Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 11, 2008 Share Posted November 11, 2008 The reason you cannot get random picks to produce all possible combinations, is because it is impossible to do it that way. You were already given a solution over a month ago on how to form all possible combinations in this thread - http://www.phpfreaks.com/forums/index.php/topic,220140.0.html Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted November 11, 2008 Author Share Posted November 11, 2008 i have tried that sir but i can not get all the teams into an array i have tried Quote Link to comment Share on other sites More sharing options...
premiso Posted November 11, 2008 Share Posted November 11, 2008 Well you need to store the matches in an array, particularly a multi-dim array I would say. So here is the logic for the below. First put all teams into an array. Next do a loop until we tell it to continue, and as long as there are more than 2 teams in the teams array this will continue. First get a random index, use that index to reference a team in the array, once that is done remove that team from the array. Rinse and repeat. We should now have 2 teams let's match them up in the team matches array. Once that is done keep repeating until there are no more or not enough teams to matchup. <?php $get_allteams = mysql_query("SELECT * FROM teams WHERE game = 'css' AND division = 'a'"); $num_teams = mysql_num_rows($get_allteams); $max_teams = $num_teams; $min_teams = 1; $team_matches = array(); // first setup a teams array $i=0; while ($team = mysql_fetch_assoc($get_allteams)) { $teams[$i++] = $team; } $continue = false; $i=0; while (!$continue) { // if there are less than 2 teams in the array, do not enter if. if (count($teams) < 2) { $index = rand(0,count($teams)) $get_home_team = $teams[$index]; unset($teams[$index]); // remove the team from the list $index = rand(0,count($teams)) $get_away_team = $teams[$index]; unset($teams[$index]); $team_matches[$i]['away'] = $get_away_team; $team_matches[$i++]['home'] = $get_home_team; }else { $continue = true; } } // lets prnt out a test print_r($team_matches); ?> Should get you what you want. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted November 11, 2008 Author Share Posted November 11, 2008 this is all i get back Array ( ) Quote Link to comment Share on other sites More sharing options...
premiso Posted November 11, 2008 Share Posted November 11, 2008 My logic was wrong on the < 2 part. It should be >= 2. Try this. <?php $get_allteams = mysql_query("SELECT * FROM teams WHERE game = 'css' AND division = 'a'"); $team_matches = array(); // first setup a teams array $i=0; while ($team = mysql_fetch_assoc($get_allteams)) { $teams[$i++] = $team; } $continue = false; $i=0; while (!$continue) { // if there are less than 2 teams in the array, do not enter if. if (count($teams) >= 2) { $index = rand(0,count($teams)) $get_home_team = $teams[$index]; unset($teams[$index]); // remove the team from the list $index = rand(0,count($teams)) $get_away_team = $teams[$index]; unset($teams[$index]); $team_matches[$i]['away'] = $get_away_team; $team_matches[$i++]['home'] = $get_home_team; }else { $continue = true; } } // lets prnt out a test print_r($team_matches); ?> Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted November 11, 2008 Author Share Posted November 11, 2008 hmmm im lookin and still Array ( ) Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted November 11, 2008 Author Share Posted November 11, 2008 sry actually i have this now Array ( [0] => Array ( [away] => [home] => Array ( [tid] => 2 [teamname] => 2 [irc] => [website] => [tag] => [bio] => [picture] => [wins] => 0 [draws] => 0 [losses] => 0 [manager] => [leader] => [scheduler] => [roundswon] => 0 [roundslost] => 0 [password] => [location] => [game] => cs16 [division] => a ) ) [1] => Array ( [away] => [home] => Array ( [tid] => 3 [teamname] => 3 [irc] => [website] => [tag] => [bio] => [picture] => [wins] => 0 [draws] => 0 [losses] => 0 [manager] => [leader] => [scheduler] => [roundswon] => 0 [roundslost] => 0 [password] => [location] => [game] => cs16 [division] => a ) ) [2] => Array ( [away] => [home] => ) [3] => Array ( [away] => [home] => ) [4] => Array ( [away] => Array ( [tid] => 1 [teamname] => unleash the beast inside [irc] => none [website] => none [tag] => utbi [bio] => [picture] => [wins] => 0 [draws] => 0 [losses] => 0 [manager] => pro[L]ax [leader] => pro[L]ax [scheduler] => pro[L]ax [roundswon] => 0 [roundslost] => 0 [password] => ****** [location] => Pacific [game] => cs16 [division] => a ) [home] => ) ) Quote Link to comment Share on other sites More sharing options...
premiso Posted November 11, 2008 Share Posted November 11, 2008 Alright I did some testing and I forgot to re-sort the array. This should work: <?php $get_allteams = mysql_query("SELECT * FROM teams WHERE game = 'css' AND division = 'a'"); $team_matches = array(); // first setup a teams array $i=0; while ($team = mysql_fetch_assoc($get_allteams)) { $teams[$i++] = $team; } $i=0; while (count($teams) >= 2) { // if there are less than 2 teams in the array, do not enter if. $index = rand(0,(count($teams) - 1)); $get_home_team = $teams[$index]; unset($teams[$index]); // remove the team from the list sort($teams); $index = rand(0,(count($teams) - 1)); $get_away_team = $teams[$index]; unset($teams[$index]); sort($teams); $team_matches[$i]['away'] = $get_away_team; $team_matches[$i++]['home'] = $get_home_team; } // lets print out a test print_r($team_matches); ?> 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.