我有一个带有一个添加按钮的表单。每当我单击添加按钮时,下一行将附加,所有输入的数据都应存储到数据库中。我可以做单条记录,但不能处理多条记录。请为我的问题提供任何帮助。提前致谢。
1066 次
2 回答
0
$this->db->insert_batch() 用于批量插入。
它是如何工作的示例(假设我要插入一系列 20 条记录):
array_push($newRecords, array(
"property1" => 1
"property2" => "two"
));
//...
array_push($newRecords, array(
"property1" => 20
"property2" => "twenty"
));
$this->db->insert_batch("tableName", $newRecords);
于 2018-05-02T05:59:21.380 回答
0
有两种不同的方法可以做到这一点:
您可以将插入代码放入 foreach
foreach($variable as $key=>$value){
$this->db->insert('table name',array('fieldname'=>'values'));
}
每次循环都调用上述方法
或使用批处理方法
$this->db->insert_batch('table name',$dataArray);
上述方法只会调用一次。
于 2018-05-02T06:02:41.363 回答