i have made a code to generate 11 digit random number and i want to save all number in database
admin_create_epin.ctp(view)
<tr>
Add E-pin:(No of E-Pin)
<td><?php echo $this->Form->input('e_pin',array('label'=>false));?></td>
</tr>
epins_controlller.php
public function admin_create_epin(){
$limit = $this->data['Epin']['e_pin'];
for($i=0;$i<$limit;$i++)
{
$random = substr(number_format(time() * rand(),0,'',''),0,11)."<br/>";
$this->data['Epin']['e_pin'] = $random;
//pr($this->data); it's show all random number
$this->Epin->save($this->data); // i have problem only here it's save only last random number
$this->Session->setFlash("Epin has been added");
$this->Redirect(array('action'=>'admin_create_epin'));
}
}
Issue:Code generate all random number but i have problem in my code insert only last random number not all and i want to insert all random number
thanks
1) You have to move
Redirect()outsite the loop.2) After the first
$this->Epin->save(...)last inserted id is stored in$this->Epin->idand then is used for update records with this id for following iterations. So you will have only one record inserted, and rewritten in the last iteration.Reset it before saving:
Also you can try
create()method: