vendredi 4 mai 2018

Randomising two teams Php Mysql

I am constructing a game where users join a code and then get split into two teams, and then answer questions. But i have one problem, Everything except the team randomiser is done. I want the users to be assigned to a team when a 'button is pressed (Not a problem, i can do this)

The problem is making the teams. As it is now im getting and displaying the current users by this line of code

if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
    while($row = mysqli_fetch_array($result)){
            echo utf8_encode("<div><br>". $row["name"]. " <b>| Lag : </b><span>" . $row["team"] . "</span><br></div>"); // för namn osv 
mysqli_close($link);
    }}}
    echo "";

I want all the users to randomly be assigned to two equally big teams, therefore i can not use a simple randomiser giving the user a 1 or a 0 because there is a chance of making the teams extremely unequal. I need to split the whole user list into two teams, random teams*.

When the user has been assigned to a team, the script will run a query updating a column called "team" for each user and then the game will start.

How can i make something that when a button is pressed, takes the users and puts all the users into two different teams? Is this done with arrays, or what? im clueless!

It is important that the teams get as equal as possible.

What should i do? I have seen things with javascript, but that doesn't work here. I hope i am clear and understandable! And thank you for taking your time reading my question:)


clarifications.

There is no Max players, there are 2 teams. I will run a query assigning the users to a team in the database.

If i have missed something, or if more information is needed, just tell me!




Aucun commentaire:

Enregistrer un commentaire