我编写了一个代码,使用codeigniter将输入数据插入到数据库中,但在插入之前,数据将通过if语句检查输入,然后如果满足条件,数据将被保存。使用if语句将数据插入数据库
我试图检查输入数据是否等于节,然后父id必须为0.否则,如果不是节,那么输入的$ data ['type']必须插入到数据库中并且父ID不能为0 。 这是我的代码。
$data = array (
'title' => $this->input->post->('title'),
'type' => $this->input->post->('type'),
'description' => $this->input->post->('description')
);
if ($data['type'] == 'section') {
$data['parent_id'] = 0;
} else {
$data['parent_id'] = $this->input->post('parent_id');
$data['type'] = $this->input->post('type');
}
$result = $this->checklist_item_model->put_item($data);
型号
public function put_item ($data) {
$this->db->insert('items', $data);
}
你的插入查询或模型代码在哪里!! – Saty
我编辑了上面的代码请看看 – claudios