如何在codeigniter中的控制器中传递foreach中的下拉值

时间:2016-09-20 07:23:15

标签: php

你好麻烦在这里总是显示错误不知道为什么请帮助我 我想在user_id和section_id中插入相同的差异,如此

from_id = 1 , assigned_for = 8 , user_id = 2, section_id = 1, month= january
from_id = 1 , assigned_for = 8 , user_id = 3, section_id = 3, month= january
from_id = 1 , assigned_for = 8 , user_id = 4, section_id = 4, month= january
from_id = 1 , assigned_for = 8 , user_id = 5, section_id = 5, month= january

在视图文件

下降数月。 选择员工的下拉列表。 标题允许权限以及仅名称 带有复选框的部分以及从标题允许权限中提取的名称下拉列表。

控制器功能

 $from = $this->_user['user_id'];
            if ($this->form_validation->run() == TRUE) {
            if ($select_section_ids) {
                foreach ($select_section_ids as $id) {$data = array(
                                'from_id' => $from,
                                'assigned_for' =>$this->input->post('assigned_for') ,
                                'user_id' => $this->input->post('user_names'),
                                'section_id' => $id,
                                'month' => $this->input->post('month'),
                            );

            $this->my_model->insert($data);
}}

'from_id' - 是登录ID  'assigned_for' - 来自精选员工的下拉列表  'user_id' - 从允许权限下拉名称  'section_id' - 来自复选框  '月' - 来自下拉

如何插入此m有错误:列'user_id'不能为空

1 个答案:

答案 0 :(得分:1)

您对用户ID使用了错误的索引名称,asyncContext.start { while(true) { // write event } } 是一个数组且等于team_lead,因此您可以使用section_ids的$ key来获取正确的section_ids

示例:

team_leads

另请注意,如果<?php foreach ($select_section_ids as $key => $id) { $data = array( 'from_id' => $from, 'assigned_for' => (isset($_POST['assigned_for']) ? $_POST['assigned_for'] : 0), 'user_id' => $_POST['team_leads'][$key], // this will use the key of section_ids, which is equal to team_leads. 'section_id' => $id, 'month' => $_POST['month'], ); ?> 不等于team_leads,则必须添加以下支票:

section_ids