我收到这个错误
Unknown column 'Array' in 'field list'
将复选框列表插入数据库时。当我执行 print_array 时,我得到了这个结果:
Array
(
[0] => Array
(
[user_id] => 3
[project_id] => 10
[project_type] => 5
[project_list] => Array
(
[0] => 17
[1] => 18
)
)
)
project_list
应该将值插入数据库中的新行。
我的看法:<input type="checkbox" value="<?php echo $project_list['id']; ?>" name="project_list[]">
这是从数据库中填充的。
我的 Controller :$this->Project_module->createProject($_POST['project_list']);
我的模块
public function createProject($project_list){
if($project_list != null){
$data = array();
foreach($project_list as $project_list){
$data[] = array(
'user_id' => $this->getUserId(),
'project_id' => $this->getProjectId(),
'project_type' => $this->getProjectType(),
'project_list' => $this->getProjectList(),
);
}
$this->db->insert_batch('tblProject', $data);
if($this->db->affected_rows()){
return true;
} else {
return false;
}
}
}
编辑 我是这样编辑我的foreach的
foreach($project_list as $row){
$data = array(
'user_id' => $this->getUserId(),
'project_id' => $this->getProjectId(),
'project_type' => $this->getProjectType(),
'project_list' => $this->getProjectList(),
);
}
但我仍然遇到同样的错误。
最佳答案
Linundus,您需要将 foreach 中的数组别名命名为不同的名称。你有
foreach ($project_list as $project_list)
你需要有这样的东西:
foreach($project_list as $list)
关于php - 错误 : Unknown column 'Array' in 'field list' (codeigniter),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44643956/