我想是的,我有一个uniq的ID呼叫NUM我想插入多发说明了这一独特NUM.我有一个动态添加文件的表单,所以我可以添加我想要的字段.当我尝试插入一行数据时,当我尝试插入多个行数据时,它无法正常工作.
我的查看页面:
<form name="codexworld_frm" action="" method="post">
<div class="field_wrapper">
<input type="text" name="num" value=""/><br />
<input type="text" name="description[]" value=""/><input type="text" name="voucher_no[]" value=""/><input type="text" name="price[]" value=""/>
<a href="javascript:void(0);" class="add_button" title="Add field"><img src="<?php echo base_url('images/add-icon.png'); ?>"/></a>
</div>
<input type="submit" name="submit" value="SUBMIT"/>
</form>
Run Code Online (Sandbox Code Playgroud)
我的控制器:
$data = array(
'no' => $this->input->post('num'),
'descriptions' => $this->input->post('description'),
'voucher' => $this->input->post('voucher_no'),
'des_price' => $this->input->post('price'),
);
$this->multi_model->form_insert($data);
$data['message'] = 'Data Inserted Successfully';
//Loading View
$this->load->view('multi_view', $data);
Run Code Online (Sandbox Code Playgroud)
我的型号:
function form_insert($data){
$this->db->insert('tbl_description', $data);
}
Run Code Online (Sandbox Code Playgroud)
如果我使用foreache循环到我的模型我认为它会工作,但我如何使用?
当我使用print_r()函数时,这是输出
1001
Array
(
[0] => description1
[1] => description2
[2] => description3
)
Array
(
[0] => voucher 1
[1] => voucher 2
[2] => voucher 3
)
Array
(
[0] => 100
[1] => 200
[2] => 300
)
Run Code Online (Sandbox Code Playgroud)
看到这个链接它是使用多个插入没有循环或你可以在控制器计数描述文章中使用你的foreach循环并通过它.
$data = array();
$count = count($this->input->post['description']);
for($i=0; $i < $count; $i++) {
$data[] = array(
'no'=>$this->input->post('num'),
'descriptions' => $this->input->post['descriptions'][$i],
'voucher' => $this->input->post['voucher'][$i],
'des_price' => $this->input->post['des_price'][$i],
);
}
$this->db->insert_batch('tbl_description', $data);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1992 次 |
| 最近记录: |