Wednesday, November 7, 2018

Cakephp: Multiple save in a for loop for cakephp

I'm using 2 databases. I fetch data from one database for a particular id from multiple tables and save it in another database. While I'm doing this, the data which requires a for loop returns the same data multiple times, instead of different data. Please help me in rectifying the error. Below is the code:

When saving data in a loop you need to call
$this->YourModel->clear();
after every save.
$q5 = $this->Model->function($empcode[$j]);
  if (!empty($q5)) {
    for ($i = 0; $i < count($q5); $i++) {
      $name = $q5[0][0]['tf_rel_fname'] . ' ' . $q5[0][0]['tf_rel_mname'] . ' ' . $q5[0][0]['tf_rel_lname'];
      $data5 = array('emp_cd' => $empcode[$j],
        'ppo_number' => $empcode[$j],
        'family_member_name' => $name,
        'relationship' => $q5[0][0]['tf_rel_cd'],
        'is_family_pensioner' => 'N',
        'dob' => date('Y-m-d', strtotime($q5[0][0]['tf_rel_dob'])),
        'disability_percentage' => $q5[0][0]['ph_disab_per'],
        'physically_handicapped' => $q5[0][0]['ph_cd'],
      );
      $this->ppmfamily_details->clear();
      $this->ppmfamily_details->create(false);
      $this->ppmfamily_details->save($data5);
    }
  }

https://stackoverflow.com/questions/41888382/multiple-save-in-a-for-loop-for-cakephp

No comments:

Post a Comment