Custom Web Applications to Grow Your Business

(256) 429-8145

Cakephp save in foreach loop

CakePHP will only save one record if save in a foreach loop or do while loop is not done properly. The CREATE function and an UNSET should be call before and after each loop iteration

foreach($parlar as $par){
	$this->request->data['Winner'] = array();
	$this->request->data['Winner']['applicant_id'] = $par['Applicant']['id'];
	$this->request->data['Winner']['game_id'] = $par['School']['id'];	
	$this->request->data['Winner']['created'] = date('Y-m-d H:i:s');