当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Set time schedule in codeigniter

问题描述:

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 have a doubt in time assignment..thats wrong

Plzz help

网友答案:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: