Jump to content

MDrone

New Members
  • Posts

    2
  • Joined

  • Last visited

MDrone's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Our disc golf league uses a little PHP script that I developed (stealing lots of code in the process) that sucks in a list of league players from a text file, lets you select the ones that show up on league day, and randomly assigns the selections into foursomes and threesomes (Demo: http://edge.byethost18.com/demo4/foursomes.php) Here's a modified example using letters of the alphabet: https://neth.roe3.org/mdrone/ABCs/foursomes.php . . . and the code: https://neth.roe3.org/mdrone/ABCs/foursomes.txt The actual version uses the shuffle() function to randomize the assignments and has a refresh button to reshuffle the assignments if a grouping contains bitter enemies. I disabled it in the example in order to show how the "A-B-C"s are assigned to the groups. As you can see, it assigns "A" to the first group, "B" to the second group, "C" to the third group and so on until it reaches the last group and then starts back at group 1 with the next letter. One of the our players wants a modification. He wants to be able to assign players into foursomes/threesomes according to their handicaps (best to worst). In other words, Group 1 would contain A, B, C, D. Group 2 would contain E, F, G, H and so on. Naturally, this would depend on which player checkboxes are selected, but the order is maintained. What I am having trouble with is getting the "A-B-C"s assigned into groups in the order they are listed in the text file. I tried using array_chunk() in the following script: https://neth.roe3.org/mdrone/ABCs/foursomes2.php . . . and the code: https://neth.roe3.org/mdrone/ABCs/foursomes2.txt In a nutshell, here's the code that's doing the work . . . $numgroups = $d; if($howmany % 4 == 0) { $numgroups = '4'; } $rows = array_chunk($players,$numgroups); $x=0; foreach ($rows as $row) { $cnt=$x+1; echo "<b><font color='#F44336'>Group ".$cnt."</font></b><br/>"; echo "<ul>"; foreach ($row as $value) { print "<li>" . $value . "\n"; } echo "</ul>"; $x++; } Unfortunately, I have a mental block when it comes to getting it to create groups like the original (which I prefer). For instance, if you select all items in the original script, Groups 6 & 7 will contain 3 items each. When you select all items in the array_chunk() version, Groups 6 & 7 contain 4 items and 2 items respectively. The same occurs if you select 10 items: the original script groups |4|3|3| and the array_chunk() version groups |4|4|2|. I'm sure there's a simple solution. I'm just not seeing it. I'm really just a hobbyist . . . not a real programmer by any stretch of the imagination. Thanks for any help anyone can send my way. BTW . . . if anyone is interested in the foursomes generator source, I'm happy to share it. It could probably use improvement.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.