在Codeigniter中使用带一个按钮保存的循环插入多行时出错

时间:2017-11-29 02:14:29

标签: php codeigniter

这是我的MODEL代码:

public function save_addition_enrollment(){


        foreach($employee as $employees)
        { 


                foreach($addition_type as $addtype)
                { 

                    if($_POST[$addtype->id."-".$employees->employee_id]){
                        $amount = $_POST[$addtype->id."-".$employees->employee_id] ;
                        $this->data = array(
                        'company_id'            => $this->input->post('company_id'),
                        'employee_id'           => $this->input->post('checkbox'),
                        'payroll_period_id'     => $this->input->post('pay_period'),
                        'other_addition_id'     => $addtype->id,
                        'amount'                => $amount,
                        'date'                  => date('Y-m-d H:i:s')
                            );  
                        $this->db->insert('other_addition_enrollment',$this->data);
                        redirect(base_url().'app/payroll_other_addition_emp_enrollment/index',$this->data);
                    }           

                 }

        }

}

我无法插入多个值的文本框我使用循环,但它不起作用你能告诉我的代码有什么不对

这是我的VIEW代码: 用于查看其代码的代码我做截图图片

enter image description here

使用1按钮保存

输出多行图像

enter image description here

1 个答案:

答案 0 :(得分:0)

我认为这个字段中的拼写错误是这样的:

$_POST["oa".$addtype->id."-".$employees->employee_id]

你必须像这样传递foreach变量:

public function save_addition_enrollment($employee){

并在这样的控制器中:

$this->model->save_addition_enrollment($arrayofemployee);
相关问题