从CodeIgniter中的子查询中获取值 [英] get value from subquery in CodeIgniter

查看:84
本文介绍了从CodeIgniter中的子查询中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是我不知道是否有办法通过更新操作从子查询中获取值,我正在尝试执行的查询看起来像这样,在我的模型的示例代码中:



the thing is that i don know if there is a way to get a value from a subquery over an update operation, the query that i'm trying to do looks like this, on a example code of my model :

$query = "UPDATE some_table SET value_1 = ((SELECT value_2 FROM other_table WHERE id = 2) + 1) WHERE id = 2";

$this->db->query($query);



i希望你能帮助我或者至少告诉我一个使用活动记录获得此替代方法



PD我正在使用CodeIgniter Framework


i hope you can help me or at least let me know an alternative way to get this using the active record

PD i'm working with the CodeIgniter Framework

推荐答案

query =UPDATE some_table SET value_1 =((SELECT value_2 FROM other_table WHERE id = 2)+ 1)WHERE id = 2;
query = "UPDATE some_table SET value_1 = ((SELECT value_2 FROM other_table WHERE id = 2) + 1) WHERE id = 2";


this-> db-> query(
this->db->query(


query);



i希望你能帮助我或者至少让我知道另一种方法来使用活动记录



PD我正在使用CodeIgniter框架


i hope you can help me or at least let me know an alternative way to get this using the active record

PD i'm working with the CodeIgniter Framework


这篇关于从CodeIgniter中的子查询中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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