You said that first and last iterations failed to insert. Was there any errors outputted? Try to output $this->Enrollment->Appointment->validationErrors array for failed data. Please remember to test this with debug level 2 so that it will output errors (if any) as well as SQL queries.
Amit Badkas
PHP Applications for E-Biz: http://www.sanisoft.com
On Wed, Dec 29, 2010 at 2:44 PM, Mark <mark.anthony.e.santos@gmail.com> wrote:
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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment