使用CI';通过带有联接子句的更新查询减少列值;的活动记录


Decrease column value via update query with join clause using CI's active record

我有两个表:

table1:iduser_idpoll_idoptions_id

table2:idpoll_idvotes

votes是一个整数,我想通过将表与一些where子句连接来更改值:

$this->db
->set('votes', 'votes - 1', FALSE)
->join('table1', 'poll_votes.options_id = table2.id')
->where('poll_id', $row)
->where('user_id', $id)
->update('table2');

我得到这个错误:

错误编号:1054"where子句"中的未知列"user_id"更新`table2`设置投票=投票-1其中`poll_id`='9'AND `user_id`='1'

试试这个:

$this->db->set('votes', 'votes - 1', FALSE)
$this->db->where('table1.user_id',$id);
$this->db->where('table2.poll_id',$row);
$this->db->update('table1 join table2 ON table1.poll_id= table2.poll_id');

尝试一下。它对我有效!!!

$data = array(
    'a.ED_FName' => $_POST['firstname'],
    'a.ED_MName' => $_POST['middlename'],
    'a.ED_LName' => $_POST['lastname'],
    'a.ED_Location' => $_POST['location'],
    'a.ED_Company' => $_POST['company'],
    'b.EMD_Department' => $_POST['department']
);
$this->db->set($data);
$this->db->where('a.EmpID', $empID);
$this->db->where('b.EmpID', $empID);
$this->db->update('tbl_employeedetails as a, tbl_employeementdetails as b');

谨致问候,TUSHAR NIRAS

更新:

注意:永远不要使用全局数组,如$_POST、$_GET,在没有安全检查的情况下直接包含用户的请求数据。这可能会导致严重的问题,如SQL注入。