If I was trying to do what you are doing, I think I might take this approach.
Create a temporary table, and populate it with team_id, league_id and location_id for the teams you want to draw to play each other.
I'd then pick 2 teams by selecting team_id,league_id,location_id, order by mt_rand() limit 2
If the location_id was the same, or the league_id was different (or whatever other parameters apply) I would discard that pairing and select another 2 at random. If the match met my criteria, I would write it to an array and delete the two teams from the temp table and start the process again. Eventually you would hopefully match all teams.
I'd use $numrows=mysql_num_rows($result) to get the number of rows returned by each query, if it was == 0 then I'd know to exit the loop, process the array and probably enter the data into a permenant table.
Hope this helps - Blu