Php 多工况代码点火器激活记录

Php 多工况代码点火器激活记录,php,mysql,codeigniter,Php,Mysql,Codeigniter,我想用和和或进行多个where查询。假设我的数组是: array (size=8) 0 => array (size=2) 'timeline.type' => string 'videos' (length=6) 'timeline.sourceId' => string '7' (length=1) 1 => array (size=2)

我想用
进行多个where查询。假设我的数组是:

array (size=8) 
      0 => array (size=2) 
              'timeline.type' => string 'videos' (length=6)                
              'timeline.sourceId' => string '7' (length=1) 
      1 => array (size=2) 
              'timeline.type' => string 'loadshedding' (length=12) 
              'timeline.sourceId' => string '5' (length=1) 
      2 => array (size=2) 
              'timeline.type' => string 'news' (length=4) 
              'timeline.sourceId' => string '3' (length=1)
      3 => array (size=2) 
              'timeline.type' => string 'news' (length=4) 
              'timeline.sourceId' => string '5' (length=1) 
上面的数组可以是动态的。我想进行如下活动记录查询:

 (timeline.type = 'videos' AND timeline.sourceId = 7) OR (timeline.type = 'loadshedding' AND timeline.sourceId = 5) OR (timeline.type = 'news' AND timeline.sourceId = 3) // and so on.
我试过:

 $this->db->select('timeline.id as postid, timeline.*, sources.*, subscription.*')->from('timeline');
 $this->db->join('sources', 'sources.type = timeline.type and timeline.sourceId = sources.id');
 $this->db->join('subscription', 'subscription.type = timeline.type and timeline.sourceId = subscription.sourceId');
 foreach($sources as $source){   //$sources is an array like given above
        $this->db->or_where($source);
 }
 $this->db->order_by("timeline.id", "DESC");
 $this->db->limit(15);

但是当我回显
$this->db->last_query()时
以查看查询。它仅返回
SELECT*FROM timeline
。可能有什么问题。谢谢。

您的代码应该是

 $sources = array (
                    0 => array ( 
                          'timeline.type' =>  'videos',             
                          'timeline.sourceId' =>  '7' ), 
                    1 => array ( 
                          'timeline.type' =>  'loadshedding',
                          'timeline.sourceId' =>  '5' ) ,
                    2 => array (
                          'timeline.type' =>  'news', 
                          'timeline.sourceId' =>  '3' ),
                    3 => array ( 
                          'timeline.type' =>  'news',
                          'timeline.sourceId' =>  '5') 
                );
end($sources);         // move the internal pointer to the end of the array
$lastkey = key($sources);  
$pr = "";
foreach($sources as $key=>$source)
{   
    if($key != $lastkey)
    {
        $pr.="( `timeline.type` = '". $source["timeline.type"] ."' and `timeline.sourceId` = " . (int) $source["timeline.sourceId"]  . ") OR ";
    }
    else
    {
        $pr.="( `timeline.type` = '". $source["timeline.type"] ."' and `timeline.sourceId` = " . (int) $source["timeline.sourceId"]  . ")";
    }   
}
$this->db->select('timeline.id as postid, timeline.*, sources.*, subscription.*')->from('timeline');
$this->db->join('sources', 'sources.type = timeline.type and timeline.sourceId = sources.id');
$this->db->join('subscription', 'subscription.type = timeline.type and timeline.sourceId = subscription.sourceId');
$this->db->where($pr);
$this->db->order_by("timeline.id", "DESC");
$this->db->limit(15);

非常感谢。不过这很容易。但我想到的是纯活动记录。@user254153对于活动记录,您可以查看codeigniter文档中的group_start()和group_end()