我已經做了代碼來生成11位隨機數字,我想保存在數據庫只有最後的隨機數插入並非所有
admin_create_epin.ctp(圖)
<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'));
}
}
問題:代碼生成所有的隨機數,但我在我的代碼插入只有最後一個隨機數並不是所有的有問題,我想插入所有隨機數
感謝
不挑剔,但我不會相信你的號碼。如果你需要一個很好的隨機分配,請使用一個經過驗證的隨機生成器,不要發明自己奇怪的操作。這是一個更好的隨機方法:'str_pad((string)mt_rand(0,99999999999),11,'0',STR_PAD_LEFT)' –
好的解決方案Emil! – freshnode
感謝@EmilVikström好的建議 –