Hello. Help please solve this problem. Project on Yii2. For example, there is a championship (video battles), from 2 to 64 people can take part. The championship is created, users submit applications and add their videos. All this is recorded in the database,
table with battles c_competition
enter image description here c_requests
enter image description here table with options c_option
enter image description here
it's all set.
The problem is that I can’t think of how to randomly split all participants into pairs, in such a way as to memorize the results (who won and who lost). And then from the winners to form more pairs and so on, until only one remains - the winner.
The voting page now looks like this
enter image description here but the options are displayed by the whole bunch, if you vote for one, then you can’t be anyone else, but I need the couples to be independent, so that you can vote for the person in each pair. I thought to do this: write a function that will take options, group them by 2 and write to another table, but I can’t figure out how to organize it. Maybe someone did something like that, please tell me.

  • one
    You have enough reputation to insert photos into the question yourself, not links to them. Do it and always, if necessary, do it - Alexey Shimansky
  • Well, you need to have some kind of Versus entity that has user1 , user2 , ratingUser1 , ratingUser2 , winner and another VersusManager that would have a stack of Versus entities (preformed) at the beginning and when all rounds of stage 1 passed formed a new stack of Versus winners. Accordingly, for each Versus entity you need to have an entry in the table (for example, c_battle or c_versus ) - Rochfort
  • @Rochfort Thank you. Here is your way turns out, issue as the answer if you wish. - Alexey

2 answers 2

Well, you need to have some kind of Versus entity that has user1 , user2 , ratingUser1 , ratingUser2 , winner and another VersusManager that would have a stack of Versus entities (preformed) at the beginning and when all rounds of stage 1 passed formed a new stack of Versus winners. Accordingly, for each Versus entity you need to have an entry in the table (for example, c_battle or c_versus )

    We need one common database with the next_tour data next_tour (the number of the next round) and next_tour_id (the participant’s id in the next round).
    Initially, the next_tour_id formed randomly. A participant without a pair and the winners of battles receive the next number for each of these fields.
    Participants of the next round should be filtered by next_tour , and the pairs should be composed of participants with the nearest next_tour_id .