Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用活动记录插入子查询的值?_Php_Sql_Codeigniter_Codeigniter 2 - Fatal编程技术网

Php 如何使用活动记录插入子查询的值?

Php 如何使用活动记录插入子查询的值?,php,sql,codeigniter,codeigniter-2,Php,Sql,Codeigniter,Codeigniter 2,我使用活动记录将值插入数据库 所有其他类型的查询我都使用自定义查询,因为它更容易,但是活动记录插入非常好 所以我有这个代码: $comment = array ( 'point_id' => $object->id, 'title' => $object->title, 'comment' => $object->comment, 'author_name' => $object->author_name, 'is_temp' =>

我使用活动记录将值插入数据库

所有其他类型的查询我都使用自定义查询,因为它更容易,但是活动记录插入非常好

所以我有这个代码:

    $comment = array (
'point_id' => $object->id,
'title' => $object->title,
'comment' => $object->comment,
'author_name' => $object->author_name,
'is_temp' => 0,
'parent_id' => $object->parent_id

);
return $this->db->insert('comments', $comment);
现在我希望能够将is_temp设置为子查询结果,即:

(SELECT allow_user_comments from subjects where id='somevalue')
一个人怎样才能做到这一点


我希望避免使用第三方库。

请随意使用。我已经用过了,而且很有效!希望它会有用。:-)

嗯,我怀疑这是你应该怎么做的,但这不是全部吗

我就是这样让它工作的(从$comment数组of Course中删除is_temp):


只是一张纸条。Codeigniter没有活动记录。它只有查询生成器。@itachi不正确。见本页第一段相关内容,可能对你有用-@Catfish这是一条误导开发者的信息。Codeigniter AR不具备正确AR的基本基础,只是查询生成器(打开它,你就会看到)。你能发布你试图实现的整个查询的sql吗?别管它了。不要忘记使用
$this->db->escape($subject\u id)
转义
$subject\u id
,因为您将其设置为
FALSE
。祝你好运
$this->db->set($comment);
$this->db->set('is_temp',
'(SELECT allow_user_comments from subjects where id='.$subject_id.')',FALSE);
$this->db->insert('comments');