I have a code for time scheduling in an interview.Interview time is 9 am to 4pm.But in between a break at 1pm to 2pm.I'm using a for loop and check 2 conditions..
controller
function appointment_schedule()
{
$start_date = $this->input->post('start_date');
$filtered_students = $this->home_model->getFilterStudents();
$fil_std_count = $filtered_students->num_rows();
$filtered_student_ids = $this->home_model->getFilterStudentsIds();
$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));
if (strtotime($end_time) > (strtotime("01:00 pm")))
{
$st_time = strtotime("02:00 pm");
$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, $start_date);
$st_time = strtotime($end_time);
}
else if (strtotime($end_time) >= strtotime("04:00 pm"))
{
$st_time = strtotime("09:00 am");
$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, $start_date);
$st_time = strtotime($end_time);
}
$filtered_students = $this->home_model->insert_appointment_schedule(date("H:i:s a", ($st_time)), $end_time, $filtered_student_ids[$i]->applicant_id, $start_date);
$st_time = strtotime($end_time);
}
}
But some looping problem..At 1 pm is reached then check the condition that is satisfied then execute that..then out the if condition.
But that enters into that first if condition then execute that condition repeatedly that reach the for loop condition.
Aucun commentaire:
Enregistrer un commentaire