【问题标题】:Codeigniter Active Record, Where inCodeigniter 活动记录,在哪里
【发布时间】:2017-10-03 04:49:18
【问题描述】:

我有一个与 where in 连接的表 我想知道是否有办法让我说这样的话:

where kd_x in (select kd_x from master_code where a='11921212')

我正在尝试使用这样的活动记录来执行此操作,但没有给我任何数据

$this->db->where_in('kd_x',array('select kd_x from MT_master where a="11921212"'));

请帮帮我,谢谢

【问题讨论】:

    标签: php sql-server codeigniter


    【解决方案1】:

    ->where() 你可以使用第二个和第三个参数,这样你就可以传递任何字符串

    $this->db->where('`kd_x`  IN (select `kd_x` from `MT_master` where a="11921212")', NULL, FALSE);
    

    //Create where clause
    $this->db->select('kd_x')
             ->where('a','11921212')
             ->from('MT_master');
    $where_clause = $this->db->get_compiled_select();
    
    //Create main query
    $this->db->select('*');
         ->from('your_table');
         ->where("`kd_x` IN ($where_clause)", NULL, FALSE);
    

    【讨论】:

      猜你喜欢
      • 2014-02-22
      • 2014-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-10
      • 2014-04-05
      • 2012-06-14
      • 2012-04-09
      相关资源
      最近更新 更多