Eme*_*ald 1 php mysql arrays codeigniter
我收到此错误
“字段列表”中的未知列“数组”
将复选框列表插入数据库时。当我做print_array 时,我得到了这个结果:
Array
(
[0] => Array
(
[user_id] => 3
[project_id] => 10
[project_type] => 5
[project_list] => Array
(
[0] => 17
[1] => 18
)
)
)
Run Code Online (Sandbox Code Playgroud)
该project_list
假定值要插入到数据库中的一个新行。
我的观点:<input type="checkbox" value="<?php echo $project_list['id']; ?>" name="project_list[]">
这是从数据库填充的。
我的控制器:$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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑 我像这样编辑了我的 foreach
foreach($project_list as $row){
$data = array(
'user_id' => $this->getUserId(),
'project_id' => $this->getProjectId(),
'project_type' => $this->getProjectType(),
'project_list' => $this->getProjectList(),
);
}
Run Code Online (Sandbox Code Playgroud)
但我仍然遇到同样的错误。
Linundus,你需要在 foreach 中为数组别名命名不同的东西。你有
foreach ($project_list as $project_list)
Run Code Online (Sandbox Code Playgroud)
你需要有这样的东西:
foreach($project_list as $list)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8994 次 |
最近记录: |