title: sequential selection in period
body: <p>In my program i need to create a work time schedule</p>
  
  <p>I have a list of personnel's like this</p>
  
  <p><a href="https://i.stack.imgur.com/x0dRr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x0dRr.png" alt="list of agents"></a></p>
  
  <p>everyone have a "Turn number" that indicate which one should be select after current one</p>
  
  <pre><code> $nextOneTurn= ($currentOneTurn % $CountOfPersonel ) +1;
  </code></pre>
  
  <p>so i can select correct one (where 'Turn' = $nextOneTurn )
  and set it in the calendar table for next day</p>
  
  <p>Challenge is How can i arrange my Program and database to: </p>
  
  <p>1- get unique "Turn number" </p>
  
  <p>2- Turn numbers should be (and maintain) always continuous  (e.g: 1-2-3-4-5)</p>
  
  <p>3- if someone edit persons and e.g: change "jan's" Turn to 3, Daniel's Turn change to 1 automatically</p>
  
  <p>4- if someone delete e.g: "pedro" , alison's Turn change to 4 automatically</p>
  
  <p>i don't Know is it correct to set all principles in program's code (PHP) or Should set some conditions in database table </p>
  
  <p>(or if this type of selection is completely wrong?)</p>
  
  <p>"Turn_number" is so Important in code. and wrong number will Bring disaster.  </p>
  
  <p>UPDATE:
  asked for code</p>
  
  <p>this is calendars table</p>
  
  <pre><code>      Schema::create('calendars', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;DATE('date');
          $table-&gt;integer('seats_id')-&gt;unsigned()-&gt;index();            
          $table-&gt;integer('historys_id')-&gt;unsigned()-&gt;index();            
          $table-&gt;integer('seats_type');            
          $table-&gt;integer('positions_id')-&gt;unsigned()-&gt;index();
          $table-&gt;integer('positions_order')-&gt;unsigned()-&gt;index();            
          $table-&gt;integer('locations_id');
          $table-&gt;integer('shifts_id');
          $table-&gt;integer('people_id')-&gt;unsigned()-&gt;index();
          $table-&gt;boolean('off')-&gt;nullable();
          $table-&gt;integer('people_id2')-&gt;unsigned()-&gt;index()-&gt;nullable();
          $table-&gt;boolean('off2')-&gt;nullable();
          $table-&gt;time('duration');
          $table-&gt;timestamps();
          });
  </code></pre>
  
  <p>and personel table:</p>
  
  <pre><code>    Schema::create('personel', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;string('name');
          $table-&gt;integer('location_id')-&gt;unsigned()-&gt;index();
          $table-&gt;string('raiting');
          $table-&gt;integer('point');  
          $table-&gt;string('flag')-&gt;nullable();
          $table-&gt;integer('order');  
          $table-&gt;boolean('multi')-&gt;nullable();                  
          $table-&gt;timestamps();
      });
  </code></pre>
  
  <p>and code to insert information to personel </p>
  
  <pre><code> $shift = DB::table('personel ')-&gt;insert(['name' =&gt; $request-&gt;name,'raiting'=&gt;$request-&gt;raiting,'point'=&gt;$request-&gt;point,'flag'=&gt;$request-  &gt;flag,'order'=&gt;$request-&gt;order]);
  </code></pre>
  
  <p>i just validate input data to be something between 1-5 (number of personel) and be uniqe.</p>