繁体   English   中英

带有连接的Codeigniter活动记录更新

[英]Codeigniter active record update with join

我有两张桌子:

table1:id,user_id,poll_id,options_id

table2:id,poll_id,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');

我收到此错误:

Error Number: 1054
Unknown column 'user_id' in 'where clause'
UPDATE `table2` SET votes = votes - 1 WHERE `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注入。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM