我无法更新数据库中的数据。我不知道发生了什么。请帮助我。显示数据按编辑按钮。但我无法编辑数据库中的数据。
我已经发布了以下代码:
Controller.php这样
public function ajax_update()
{
$data = array(
'placename' => $this->input->post('placename'),
'description' => $this->input->post('description'),
'tel' => $this->input->post('tel'),
'latitude' => $this->input->post('latitude'),
'longtitude' => $this->input->post('longtitude'),
'placetype_id' => $this->input->post('placetype_id'),
'province_id' => $this->input->post('province_id'),
);
$this->tblplace->update(array('placeid' => $this->input->post('placeid')), $data);
echo json_encode(array("status" => TRUE));
}
Modal.php
public function save($data)
{
$this->db->insert('tblplace', $data);
return $this->db->insert_id();
}
public function update($where, $data)
{
$this->db->update('tblplace', $data, $where);
return $this->db->affected_rows();
}
我可以从数据库中获取数据以显示在文本框中。但无法更新数据。我需要帮助。谢谢。
答案 0 :(得分:0)
你的控制器:
= 0 LIMIT 100000,1001;
在模特:
+------+--------------+-----------------------+--------+---------------------------------------------------+---------------+---------+--------------------------------------------------+----------+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+--------------+-----------------------+--------+---------------------------------------------------+---------------+---------+--------------------------------------------------+----------+----------+-------------+
| 1 | PRIMARY | externallinks_global | ALL | APIINDEX3,APIINDEX4,APIINDEX6,APIINDEX2,APIINDEX5 | NULL | NULL | NULL | 27193330 | 100.00 | Using where |
| 1 | PRIMARY | externallinks_paywall | eq_ref | PRIMARY | PRIMARY | 4 | s51059__cyberbot.externallinks_global.paywall_id | 1 | 100.00 | |
| 2 | MATERIALIZED | externallinks_paywall | ref | PRIMARY,PAYWALLSTATUS | PAYWALLSTATUS | 1 | const | 768 | 100.00 | Using index |
+------+--------------+-----------------------+--------+---------------------------------------------------+---------------+---------+--------------------------------------------------+----------+----------+-------------+
3 rows in set, 1 warning (0.00 sec)
希望这很清楚,它可以帮助您更新数据。
答案 1 :(得分:0)
更新功能中没有where
条件
public function update($where, $data)
{
$this->db->where($where);
$this->db->update('tblplace', $data);
return $this->db->affected_rows();
}