PHP and Mysql Division without rest in PHP division of tasks

0

Everyone needs to assign tasks to a variable number of participants. EX: Through a select I get 49 tasks to be executed and I have to distribute to 4 employees. In other words, the division would be 1st employee would have 12 tasks the 2nd employee would have 12 tasks the 3rd employee would have 12 tasks and the 4th employee would have 13 tasks that would be the rest. Both the amount of tasks and how many employees come from a select can vary and each task and employee has a unique code. Employee 1 task 1 Employee 1 task 2 and so by completing 12 days, I would switch to another with 12 more ...

I'm using PHP PDO Mysql and I need to do a loop that does this distribution the way I explained but I do not know how to do it. if anyone can help me I will be very grateful.

    
asked by anonymous 01.03.2018 / 17:56

1 answer

0

Friend,

I did it here but could not compile. I believe it is enough for you to enterder the logic that I applied ... I hope it helps you!

<?php

  $qtdTarefas = 49;
  $qtdFuncionarios = 4;
  $aux = 0;

  while($qtdTarefas != 0){ //Enquanto existir tarefa...
    $funcionario[$aux] = recebeTarefa(); //Funcionario recebe a tarefa
    if(($qtdTarefas - 2) < 0){//Se essa for a penultima tarela da lista
      $qtdTarefas--;
      $funcionario[$aux] = recebeTarefa();//O mesmo funcionario recebe essa outra tarefa
      break;//Para o loop
    } else {
      $qtdTarefas--;
      $aux++;
      if ($aux > $qtdFuncionarios){ //Volta ao funcionario 0 quando chega no ultimo
        $aux = 0;
      }
    }
  }

 ?>

Hugs

    
01.03.2018 / 18:16