带连接的 Codeigniter 活动记录更新

Codeigniter active record update with join(带连接的 Codeigniter 活动记录更新)
本文介绍了带连接的 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 活动记录更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)