0

我试图创建一个活动查询,其中子查询中有一个变量

$fb_UID = $this->session->userdata('fb_UID');

$qs = $this->db->select("*,qs.UID as qs_UID")->
from("question_set qs")->
join("questions q","qs.UID=q.fk_question_set_UID","inner")->
where("sickness_UID",$id)->
where('`qs.UID` NOT IN(SELECT `fk_question_set_UID` FROM `solved_qset` where fk_fb_UID = `$fb_UID`)', NULL, FALSE)->
group_by("qs.UID","asc")->
order_by("qs.UID","random")->
get()->row();

但我得到一个错误

Unknown column '$fb_UID' in 'where clause'

有没有办法在活动记录子查询中正确放置变量?

谢谢

4

2 回答 2

0

请尝试此代码,并连接变量:

$fb_UID = $this->session->userdata('fb_UID');    
$qs = $this->db
     ->select("*,qs.UID as qs_UID")
     ->from("question_set qs")
     ->join("questions q","qs.UID=q.fk_question_set_UID","inner")
     ->where("sickness_UID",$id)
     ->where('`qs.UID` NOT IN(SELECT `fk_question_set_UID`
               FROM `solved_qset` where fk_fb_UID = '.$fb_UID.')', NULL, FALSE)
     ->group_by("qs.UID","asc")
     ->order_by("qs.UID","random")
     ->get()->row();
于 2013-10-28T09:10:26.153 回答
0

试试这个代码。我认为你不能组合许多单引号。如果你在外面使用单引号,你应该在这个单引号里面使用双引号,当双引号在外面时也是如此。

where('"qs.UID" NOT IN(SELECT "fk_question_set_UID" 
FROM "solved_qset" where fk_fb_UID = "$fb_UID")', NULL, FALSE)->// try this....
于 2013-10-08T02:25:28.107 回答