我有一个这样的模型功能: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