2016-08-25 61 views
1

错误看起来是这样的:MySQL错误,同时更新

未知列 '在' resignation_id ='158 'where子句'

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'; 
 
}

还附上表格图像enter image description here

+2

放错位置的反引号〜似乎是围绕所有的“resignation_id =‘158’”反引号 – RamRaider

+0

你的表告诉你正在使用resignation_id1代替resignation_id的。 更改它。 – Manish

+0

@Manish是什么?这是正确的。 –

回答

1

你可以写你的活动记录格式查询作为

$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(); 
1

在你的查询中删除周围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'; 
} 
+0

请给出查询,因为有变量替换 – shank

+0

我添加了模型代码,正确使用'$ this-> db-> where()' – roberto06

+0

谢谢..伙计 – shank

0

尝试这样

$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); 
+0

未知列'where子句中''resignation_id ='158'' UPDATE pr_temporary_absconding_checklists SET'completion_status' = NULL WHERE'resignation_id ='158'' AND checklist_id ='4' – shank

+0

@shank现在检查 –

0

你应该试试这段代码。根据最终的sql语句在SQL

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'; 
    }