Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
YII插入多个动态行_Yii - Fatal编程技术网

YII插入多个动态行

YII插入多个动态行,yii,Yii,这是我在view/_form.php中的代码 <tr> <td> <?php $criteria = new CDbCriteria; $criteria->order = 'ScriptArgumentClassType'; //or whatever field echo CHtml::activeDropDownList($meta,**'[]ScriptArgumentClass_id'**,CHtml::listD

这是我在view/_form.php中的代码

<tr>
  <td>
    <?php
    $criteria = new CDbCriteria;
    $criteria->order = 'ScriptArgumentClassType'; //or whatever field
    echo CHtml::activeDropDownList($meta,**'[]ScriptArgumentClass_id'**,CHtml::listData(AutoScriptArgumentClass::model()->findAll`enter code here`($criteria),'id','ScriptArgumentClassType'), array('prompt'=>'Please select Argument class type'));
    ?>  
  </td>
  <td>
    <?php
    $criteria = new CDbCriteria;
    $criteria->order = 'TnType'; //or whatever field
    echo CHtml::activeDropDownList($meta,**'[]Type_id'**,CHtml::listData(AutoTnType::model()->findAll($criteria),'id','TnType'), array('prompt'=>'Please select TN type'));
    ?>
  </td>

  <td>
    <?php
    $criteria = new CDbCriteria;
    $criteria->order = 'service'; //or whatever field
    echo CHtml::activeDropDownList($meta,'**'[]Service_id'**,CHtml::listData(Service::model()->findAll($criteria),'id','service'), array('prompt'=>'Please select Service'));
    ?>
  </td>

  <td>
    <?php
    $criteria = new CDbCriteria;
    $criteria->order = 'Manufacture'; //or whatever field
    echo CHtml::activeDropDownList($meta,'**[]Cpe_id'**,CHtml::listData(AutoCPE::model()->findAll($criteria),'id','Manufacture'), array('prompt'=>'Please select CPE'));
    ?>
  </td>
</tr>
这里我正在做foreach,以便将多行插入到一个表中。
它以这种方式插入2个输入的行值

1 0 0 0
0200
030
02
1 0 0 0
0300
040
02

而不是

1232
1 3 4 2

它不是插入2行,而是插入8行,每行带有一个列值

请参见粗体(****)中的代码。这就是我将它声明为数组的方式


感谢您的帮助。如果你需要更多的细节,请告诉我

这里的问题很简单

发生的情况是,jquery对每个属性发出post请求,或者换句话说,对数据库中单个列的数据发出post请求。这就是为什么在每个元数据变量中只得到一个字段集,该字段集对应于一个post请求

因此,您可以在保存之前合并4-4个请求..或者让jquery提交所有4个下拉列表值

我能为你做的第一件事

$metadatas=$_POST['AutoTestScriptMeta'];
$iterations=count($metadata)/4;
$clubbed_array=array();
for($i=0;$i<$iterations;$i++)
{
    array_push($clubbed_array,array($metadata[$i*4+0][0],$metadata[$i*4+1][1],$metadata[$i*4+2][2],$metadata[$i*4+3][3]));
}

foreach ($clubbed_array as $clubbed_value ) {
      $meta=new AutoTestScriptMeta;
      $meta->attributes = $clubbed_value;
      $meta->save();
}
$metadatas=$\u POST['AutoTestScriptMeta'];
$iterations=计数($metadata)/4;
$clubbed_数组=数组();
对于($i=0;$iattributes=$clubbed_值;
$meta->save();
}

你能给我们一个$\u POST数组的var\u dump()/print\r()来查看实际发布的内容吗?这是print\r数组([ScriptArgumentClass\u id]=>array([0]=>4[1]=>1)[Type\u id]=>array([0]=>3[1]=>3)[Service\u id]=>array([0]=>1[1]=>4][Cpe\u id]=>Array([0]=>1[1]=>2))问题解决了,我可以保存记录了。谢谢,现在我已经看到了你的答案。当我填写两行并给出vardump时,我会让你知道它给出了这个数组(1){[0]=>Array(4){[0]=>NULL[1]=>NULL[2]=>NULL[3]=>NULL}
$metadatas=$_POST['AutoTestScriptMeta'];
$iterations=count($metadata)/4;
$clubbed_array=array();
for($i=0;$i<$iterations;$i++)
{
    array_push($clubbed_array,array($metadata[$i*4+0][0],$metadata[$i*4+1][1],$metadata[$i*4+2][2],$metadata[$i*4+3][3]));
}

foreach ($clubbed_array as $clubbed_value ) {
      $meta=new AutoTestScriptMeta;
      $meta->attributes = $clubbed_value;
      $meta->save();
}