chriscloyd Posted May 13, 2006 Share Posted May 13, 2006 okay say i got 40 teams i wanna learn how to write the script where it randomly pairs two teams up to eachother 8 times but 8 dif teams not the same team as it paired up to b4 can someone help me? and then i want it to post into a table or file Quote Link to comment Share on other sites More sharing options...
448191 Posted May 13, 2006 Share Posted May 13, 2006 [!--quoteo(post=373420:date=May 13 2006, 12:13 AM:name=chriscloyd)--][div class=\'quotetop\']QUOTE(chriscloyd @ May 13 2006, 12:13 AM) [snapback]373420[/snapback][/div][div class=\'quotemain\'][!--quotec--]okay say i got 40 teams i wanna learn how to write the script where it randomly pairs two teams up to eachother 8 times but 8 dif teams not the same team as it paired up to b4 can someone help me? and then i want it to post into a table or file[/quote]This will get you two random id's from a table:[b]SELECT team_id FROM table1 WHERE ORDER BY RAND() LIMIT 2;[/b]The rest of your question I don't understand. Try using proper centences. Quote Link to comment Share on other sites More sharing options...
.josh Posted May 13, 2006 Share Posted May 13, 2006 while i do understand your question, please note that we are not here to write your code for you. you need to make an effort to write your own code, and we will help you fix bugs....HOWEVER... since I was extremely bored, I decided to do it anyways. Merry Christmas.[code]<?php//generic array holding 40 values$list = array('one','two','three','four','five', 'six','seven','eight','nine','ten', 'eleven','twelve','thirteen','fourteen','fifteen', 'sixteen','seventeen','eighteen','nineteen','twenty', 'twentyone','twentytwo','twentythree','twentyfour','twentyfive', 'twentysix','twentyseven','twentyeight','twentynine','thirty', 'thirtyone','thirtytwo','thirtythree','thirtyfour','thirtyfive', 'thirtysix','thirtyseven','thirtyeight','thirtynine','fourty');$max = 39; //starting amount of items (0-39 = 40) // since you have 40 items you want to pair off, we will // do the 'pair-off 20 timesfor ($count = 0;$count <20; $count++) { //pick 2 random items from the list //and remove them from the list for ($number = 0; $number < 2; $number++) { $randompick = rand(0,$max); $numberpair[$number] = $list[$randompick]; unset($list[$randompick]); $list = array_values($list); $max--; } //make a list of the items paired up $pairups[] = array('first' => $numberpair[0], 'second' => $numberpair[1]);}//generic printout of the list$listofpairs = "<table border='1'><tr>";$listofpairs.= "<td><b>First</b></td><td><b>Second</b></td></tr>";for ($pairs = 0; $pairs < 20; $pairs++) { $listofpairs.="<tr>"; foreach ($pairups[$pairs] as $val) { $listofpairs.="<td>" . $val . "</td>"; } $listofpairs.="</tr>";}$listofpairs.="</table>";echo $listofpairs;?>[/code]if you have your items in a database then you would select them the way you normally would and replace the $list array with an array of the values pulled from the database. 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.