带连接的 Codeigniter 活动记录更新

我有两张桌子:

table1:id、user_id、poll_id、options_id

table2: id, poll_id, votes

column 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)->更新('table2');

我收到此错误:

<上一页>错误号:1054'where 子句'中的未知列'user_id'更新 `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');

i have two tables:

table1: id, user_id, poll_id, options_id

table2: id, poll_id, votes

column votes is an integer and i want to change the value by joining the tables with some where clauses:

$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');

I´m getting this error:

Error Number: 1054
Unknown column 'user_id' in 'where clause'
UPDATE `table2` SET votes = votes - 1 WHERE `poll_id` = '9' AND `user_id` = '1'

解决方案

Try this one:

$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');

相关文章