【发布时间】:2014-01-16 13:35:00
【问题描述】:
我在我的 Codeigniter 控制器中将一些数据插入到数据库中
function addsoothingmemory() {
$config['upload_path'] = './uploads2/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '500000';
$config['max_width'] = '100024';
$config['max_height'] = '100768';
$this->upload->initialize($config);
if (!$this->upload->do_upload()) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('soothing', $error);
} else {
$imagedata = $this->upload->data();
$data = array(
'image_path' => $imagedata['file_name'],
'title' => $this->input->post('title'),
'user_id' => $this->session->userdata("user_id"),
'feelingrate' => $this->session->userdata("feelingrate"),
'description' => $this->input->post('description')
);
$query = $this->favourite_db->getsoothingcount() + 1;
$this->favourite_db->add_soothingmemory($data);
$count = array('soothingcount' => $query);
$this->favourite_db->updateusercount($count);
$this->load->view('positivepast', $data);
}
}
型号
function add_soothingmemory($data) {
$this->load->database();
$this->db->insert('soothingmemory', $data);
$this->set_session();
return $data;
}
问题是当值被插入到数据库中时,它会插入三次,创建多个/重复的行。
【问题讨论】:
-
在你的模型中你写了
return $data;,但在你的控制器中它在哪里捕获$data,因为$this->favourite_db->add_soothingmemory($data);没有分配给任何变量? -
你建议我做什么?
-
`$query = $this->favourite_db->getsoothingcount() + 1;` 有什么作用?
-
getsoothingcount() 用于更新数据库中的用户访问次数
-
$this->favourite_db->updateusercount($count);增加了多少分贝值?
标签: php mysql codeigniter