PHP and Mysql Division without rest in PHP task division

Asked

Viewed 101 times

0

Galley is the following need to assign tasks to a variable number of participants. EX: Through a select I got 49 tasks to be executed and I have to distribute to 4 employees. In other words the division would be like this first employee would have 12 tasks the 2nd employee would have 12 tasks the third official would have 12 tasks and the 4th employee would have 13 tasks that would be the rest. Both the number of tasks how many employees come from a select can vary and each task and employee has a unique code. Official 1 task 1 Official 1 task 2 and so until I turn 12 then I would pass to the other with 12 more...

I am using PHP PDO Mysql and need to make a loop that makes this distribution the way I explained but do not know how to do. if any can help me I’ll be very grateful.

1 answer

0


Friend,

I did it here, but I couldn’t compile it. I believe it’s enough for you to understand the logic 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.