删除post方法并为php codeigniter中的每个循环初始化 [英] Remove post method and initialize for each loop in php codeigniter

查看:24
本文介绍了删除post方法并为php codeigniter中的每个循环初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除 input-> post 行中的 $ attain = $ this-> input-> post('mytext',true); .有很多方法,但是会显示错误.如何摆脱这种张贴方法?

I want to remove input->post at the line $attain = $this->input->post('mytext', true); .Itried this with many ways but errors display. How can I get rid of this post method?

$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); 

        //}
    }

这是我在其中用户产生动态输入的视图

This is my view where user produce dynamic inputs

    </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>

这是3个值保存在数据库中的方式

This is how 3values save in the database

推荐答案

从上面的评论中,我认为您的麻烦是相同的数据多次插入.如果是这样,

From your comments above i think your trouble is that the same data is inserting multiple times. If this is the case,

我认为您错过了一个右括号.尝试在循环外尝试 $ this-> db-> insert_batch('projectem',$ data2);

I think u missed a closing bracket .Try $this->db->insert_batch('projectem', $data2); outside the loop

$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);

这篇关于删除post方法并为php codeigniter中的每个循环初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆