Hi everyone,

I just need some help on inserting records using loops.

To give you an overview, I have programs that run for a certain number
of days and this code will insert a separate row for each appointment
record. The problem is that the loop fails at the first iteration.
Another weird thing is that when the number of appointments is 20+, it
will fail both the first and the 20th+ iterations. (rows 2-19 get
inserted just fine).

I've tried looking for other topics involving save and loops, but
still couldn't find a solution.

I'm placing here the code for your reference.

Thank you in advance,
Mark


//PHP Code Starts Here
$program = $this->Enrollment->Program->read(null, $this-
>data['Enrollment']['program_id']);

for($i=1;$i<=$program['Program']['no_of_appointments'];$i++) {
        $appointment = array(
                                'appointment_no' => $i,
                                'appointment_date' => array('month' => 
date('m'), 'day' =>
date('d'), 'year' => date('Y')),
                                'employee_id' => 
$this->data['Enrollment']['employee_id'],
                                'enrollment_id' => $enrollment_id
                                );
        $this->Enrollment->Appointment->create(false);
        if($this->Enrollment->Appointment->save($appointment)) {
                debug("Saved #$i");
        } else {
                debug("Failed #$i");
        }
}

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to