【发布时间】:2013-12-30 07:30:05
【问题描述】:
我需要使用 codeigniter 在同一字段上运行条件为 where 和 or_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