Set time schedule in CodeIgniter

2019-05-29 00:59发布

问题:

I have a list of students and a common button Appointment Schedule.

When i click the button set the time schedule for each student is inserted int db

Now i set start time as 9 am .

schedule appointment for all students in that table with 20 min time gap.

controller

   function appointment_schedule()
  {
  $filtered_students = $this->home_model->getFilterStudents();
  $fil_std_count=$filtered_students->num_rows();
  $filtered_student_ids = $this->home_model->getFilterStudentsIds();
     $total_time=$fil_std_count*20;
     if($total_time<=240)
     {
         $st_time = strtotime("09:00 am");
         for($i=0;$i<$fil_std_count;$i++)
         {
             $end_time = date("H:i:s a", strtotime('+20 minutes', $st_time));
             $filtered_students = $this->home_model->insert_appointment_schedule(date("H:i:s a", ($st_time)),$end_time,$filtered_student_ids[$i]->applicant_id); 
             $st_time = strtotime($end_time);
         }
     }
     if($total_time>240 && $total_time <= 360)
     {
          $st_time = strtotime("02:00 pm");
          for($i=13;$i<$fil_std_count;$i++)
          {
             $end_time = date("H:i:s a", strtotime('+20 minutes', $st_time));
             $filtered_students = $this->home_model->insert_appointment_schedule(date("H:i:s a", ($st_time)),  $end_time,$filtered_student_ids[$i]->applicant_id); 
             $st_time = strtotime($end_time);
          }  
     }
   redirect(base_url().'home/get_filtered_students','refresh');
}

But I wonder if that's wrong?

回答1:

try with this

$st_time = strtotime("09:00 am"); 

replace for loop ,

$st_time = strtotime("09:00");
for($i=0;$i<$fil_std_count;$i++)
{
     $st_time=$st_time;
     $end_time = date("H:i:s a", strtotime('+20 minutes', $st_time));
     $filtered_students = $this->home_model->insert_appointment_schedule(date("H:i:s a", ($st_time)),$end_time); 
     $st_time = strtotime($end_time);
}

so end time will have +20 Minutes to current value of $st_time