Alright So I have my database
and it can pull off foreign key to associate different players with different groups.
Now, I want to make 2 teams within the group off of data from the column "Golfer_handicap"
and split the number of golfers equally, with the closest possible handicaps between the 2 teams (eg. Team 1 avg hadicap = 10.7, Team 2 avg Handicap 10.5). So essentially, I want to pull each golfer, only use them once, and sort them into equal teams.
What I can figure out:
I need to sort golfers low value to high value (high value being the worst). I am newer into coding, all self taught, so I'm not sure how to sort SQL
data yet. Here is my SQL
to pull the data in general:
$sql = "SELECT golfer_name, golfer_handicap, golfer_ghin FROM golfers WHERE trip_name_table_ID = '$userid'";
$result = $mysqli->query($sql);
I'm thinking I may also have to use an AVG
call too? I used it in a different capacity, which was to call the average handicap of all golfers in the group, and that worked great:
$sql2 = "SELECT CAST(AVG(golfer_handicap) AS DECIMAL (3,1)) AS handicap FROM golfers WHERE trip_name_table_ID = '$userid'";
$result2 = $mysqli->query($sql2);
$average = mysqli_fetch_array($result2);
Any help is great. Looking to use PHP to echo
the results. Thanks
Note: I know about the SQL injections risk. When the time comes, before setting the site anywhere close to live, I will address that. This is to figure out how to answer the question I asked above. NOT about security.