【问题标题】:how to use multiple or_where on same field in codeigniter如何在codeigniter中的同一字段上使用多个or_where
【发布时间】:2013-12-30 07:30:05
【问题描述】:

我需要使用 codeigniter 在同一字段上运行条件为 whereor_where 的查询。有操作执行其他字段的地方。代码,

function get_newTapal($off, $status)        
{   
  $p = $this->db->select('*')
        ->from('tbl_tapal')
    ->join('tbl_subjectmain', 'tbl_subjectmain.Msub_Cd = tbl_tapal.Tmain_sub')
    ->join('tbl_subject_all', 'tbl_subject_all.Sub_Cd = tbl_tapal.Tsub_sub')
    ->join('tbl_seat', 'tbl_seat.SeatCd = tbl_tapal.Tseat')
    ->where('tbl_tapal.Tstatus', $status)
    ->where('tbl_tapal.Toffice_id', $off)
    ->where('tbl_tapal.Tmain_sub !=', 1)
    ->where('tbl_tapal.Tsub_sub !=', 2) 
    ->or_where('tbl_tapal.Tstatus', 2)
    ;
    $query = $p->get();
    $new_tapal=$query->result();    
    foreach($new_tapal as $row){    echo $row->Toffice_id.'/'.$row->Tapal_no.'/'.$row->Tyear.'<br>';    }
}

当我在没有or_where 条件的情况下运行查询时,它会根据代码正常工作。我需要满足状态值为“1”或“2”的所有where 条件的行。但是当我添加or_where 条件时,它不会检查该部分查询的其他条件。即,查询返回同时满足前 4 个 where 条件的行以及仅满足 or_where 条件的行。
有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: codeigniter


    【解决方案1】:

    您可以使用$this-&gt;db-&gt;or_where_in() 来检查其中的倍数或条件。

    例如:

    $status= array('1', '2', '3');
    $this->db->or_where_in('tbl_tapal.Tstatus', $status);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-13
      • 2019-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-06
      • 2023-03-08
      相关资源
      最近更新 更多