Mysql 更新时出错

Mysql error while updating

错误 看起来像这样:

Unknown column 'resignation_id='158'' in 'where clause'

UPDATE pr_temporary_absconding_checklists SET completion_status = 'pending' WHEREresignation_id='158' AND checklist_id='4'

我的型号代码是:

function submit_absconding_checklist($post_array, $idss) {

  $this->load->database();
  $ids = $this->uri->segment(4);
  $where = "resignation_id='$ids' AND checklist_id='$idss'";
  $this->db->where($where);
  $dbdata = array(
    "completion_status" => $post_array['completion_status']
  );

  $this->db->update('pr_temporary_absconding_checklists', $dbdata);
  print_r($query);
  die;
  /**
   * if required add this code here to check
   *
   * echo $this->db->last_query();
   */
  return 'Checklist updated successfully';
}

还附上table图片:

删除查询中 resignation_id='158' 周围的反引号。

它应该是这样的:

UPDATE `pr_temporary_absconding_checklists` SET `completion_status` = 'pending' WHERE `resignation_id`='158' AND `checklist_id`='4'

型号代码:

function submit_absconding_checklist($post_array, $idss) {

  $this->load->database();
  $ids = $this->uri->segment(4);
  $this->db->where('resignation_id', $ids); // UPDATED
  $this->db->where('checklist_id', $idss); // UPDATED
  $dbdata = array(
    "completion_status" => $post_array['completion_status']
  );

  $this->db->update('pr_temporary_absconding_checklists', $dbdata);
  print_r($query);
  die;
  /**
   * if required add this code here to check
   *
   * echo $this->db->last_query();
   */
  return 'Checklist updated successfully';
}

这样试试

$data = array(
    'completion_status' => $post_array['completion_status']
);

$this->db->where('resignation_id', $ids);
$this->db->where('checklist_id', $idss);
$this->db->update('mytable', $data);

您可以将查询以 Active Record 格式编写为

$this->db->set("completion_statuscompletion_status", $post_array['completion_status']);
$this->db->where("resignation_id", $ids);
$this->db->where("checklist_id", $idss);
$this->db->update("pr_temporary_absconding_checklists");
$afftectedRows = $this->db->affected_rows();

你应该试试这个代码。

function submit_absconding_checklist($post_array, $idss) {
    $this->load->database();
    $ids = $this->uri->segment(4);
    $dbdata["completion_status"] = $post_array['completion_status'];
    $this->db->update("pr_temporary_absconding_checklists", $dbdata, array('resignation_id' => $ids,'checklist_id'=>$idss));

    print_r($query);
    die;
    /**
      * if required add this code here to check
      *
      * echo $this->db->last_query();
    */
    return 'Checklist updated successfully';
  }