带连接的 Codeigniter 活动记录更新 [英] Codeigniter active record update with join

查看:42
本文介绍了带连接的 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');

这篇关于带连接的 Codeigniter 活动记录更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆