我有一個這樣的模型功能:CodeIgniter的Active Record的IF語句
function get_dtsample083($dt_date_production,$dt_filler) {
$this->db1->select('detail_id_sample as detail_id083, detail_id as detail_id_mic, detail_id_sample087_096, headerid_sample, sampling_time, sample_code, product_id, temp, filler, ph, csp_la_35, csp_la_55, tab, operator, remark, rough_mic');
$this->db1->from('tb_lqs083dtl');
$this->db1->join('tb_lqs083hdr', 'tb_lqs083hdr.headerid = tb_lqs083dtl.headerid');
$this->db1->where('tb_lqs083hdr.date_production',$dt_date_production);
$this->db1->where('tb_lqs083hdr.filler',$dt_filler);
$try1 = 'Finished Product Coconut Cream';
$try2 = 'Finished Product';
if($this->db1->where('tb_lqs083hdr.product_type',$try1)) {
$this->db1->where('tb_lqs083hdr.product_type',$try1);
$this->db1->where('tb_lqs083dtl.stdtl','1');
$this->db1->order_by("tb_lqs083dtl.headerid_sample", "asc");
$this->db1->order_by("tb_lqs083dtl.detail_id_sample087_096", "asc");
$this->db1->order_by("tb_lqs083hdr.temp", "asc");
} elseif($this->db1->where('tb_lqs083hdr.product_type !=',$try1)) {
$this->db1->where('tb_lqs083hdr.product_type',$try2);
$this->db1->where('tb_lqs083hdr.product_name','Coconut Cream');
$this->db1->where('tb_lqs083dtl.stdtl','1');
$this->db1->order_by("tb_lqs083dtl.headerid_sample", "asc");
$this->db1->order_by("tb_lqs083dtl.detail_id_sample087_096", "asc");
$this->db1->order_by("tb_lqs083hdr.temp", "asc");
} else {}
$query = $this->db1->get();
echo $this->db1->last_query();
if ($query->num_rows() > 0) {
return $query->result();
}
}
第一,如果總是在執行查詢執行的語句,我希望第二個if語句也正在執行。
我有查詢條件:
如果列
tb_lqs083hdr.product_type = 'Finished Product Coconut Cream'
然後第一個if語句將被執行。else if if
tb_lqs083hdr.product_type = 'Finished Product'
then second if statement will be executed。
兩個條件似乎彼此相似,但在我的表中,兩個條件都有不同的值。
我仍在評估我的查詢。所以任何幫助,將不勝感激。
謝謝。
好吧,我會嘗試使用你的建議,希望它能工作 – metaphor
也許這樣的事情?見下面的答案: – PaulD