你好,我有麻烦,这里总是显示错误,不知道为什么,请帮助我我想在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' -来自select employee的下拉菜单'user_id' -来自允许权限的名称下拉列表'section_id' -来自复选框'month'-从下拉菜单
如何插入这个m有错误:列'user_id'不能为空
您使用了错误的用户id索引名称,team_lead
是一个数组,等于section_ids
,因此您可以使用section_ids
的$key来获得正确的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
,那么您必须像这样添加检查:
'user_id' => isset($_POST['team_leads'][$key]) ? $_POST['team_leads'][$key] : 0,