循环,以节省每列字段picture1pic6:CakePHP的唯一的循环保存数据的第一行,其他行不节能
请帮帮忙,用我的蛋糕PHP版本2.0,尽量做到循环,以节省每一列,但只第一行数据保存,数据应该像附图1一样保存。希望有人能帮忙,我试图弄清楚2周。 V_COUNT我硬编码到23
if($this->IPI->save($this->request->data))
{
$table_name = 'IPI_V';
$this->IPI->setSource($table_name);
for($i=1;$i<=$this->request->data['IPI']['V_COUNT'];$i++)
{
if($i<10){$i = '0'. $i;}
if(($this->request->data['IPI']['Quantity'.$i])!=NULL)
{
$this->request->data['IPI']['Type_Defect'] = $this->request->data['IPI']['Type_Defect'.$i];
$this->request->data['IPI']['CAT'] = $this->request->data['IPI']['CAT'.$i];
$this->request->data['IPI']['Defect'] = $this->request->data['IPI']['Defect'.$i];
$this->request->data['IPI']['Quantity'] = $this->request->data['IPI']['Quantity'.$i];
$this->IPI->create();
$this->IPI->save($this->request->data);
}
}
代替如果(($这 - >请求 - >数据[ 'IPI'] [ '数量'。$ I]) != NULL)尝试使用if(!empty($ this-> request-> data ['IPI'] ['Quantity'] [$ i]))否则请分享您在请求中获得的输出 –
Dear Rohit,结果仍然一样,只保存了一行,这段代码我已经尝试过了,输出请参考picture2。 – user3719378
好的,你可以请一个pr($ this-> request-> data)并显示你的请求数据的输出。 –