我想在 $ achie = $ this-> input-> post(' mytext',true)一行中删除输入>帖子 ; 。用多种方式测试,但显示错误。我该怎样摆脱这个帖子的方法?
$attain = $this->input->post('mytext', true);
$data2=array(); //<-initialize
foreach ($attain as $i => $a) { // need index to match other properties
//append array
$data2[] = array(
'mytext' => $a,
'projectname'=> $this->input->post('projectname'),
);
//for multiple entry in same table
$this->db->insert_batch('projectem', $data2);
//}
}
这是我用户生成动态输入的视图
</script>
<script type="text/javascript">
$(document).ready(function() {
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initlal text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append('</br><div><input class="input form-control"" name="mytext[]"/><a href="#" class="remove_field">Remove</a></div>'); //add input box
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
})
});
</script>
<div class="input_fields_wrap">
<div class="form-group">
<button type="button" class="btn btn-success add_field_button">Add More Fields</button>
</div>
</div>
答案 0 :(得分:0)
从您上面的评论我认为您的麻烦是相同的数据插入多次。如果是这种情况,
我想你错过了一个结束括号。在循环外试试$this->db->insert_batch('projectem', $data2);
$attain = $this->input->post('mytext', true);
$data2 = array(); //<-initialize
foreach($attain as $i => $a)
{
$data2[] = array(
'mytext' => $a,
'projectname' => $this->input->post('projectname') ,
);
} // modification here
/*
* if the insert_batch is inside the loop, insert will
* occur multiple times with
*/
$this->db->insert_batch('projectem', $data2);