我必须执行查询以检查变量是否为空。喜欢:
if($symbol == ""){
$data_array = $this->db->select('*')
->select_max('date')
->get('company')
->row_array();
}else{
$data_array = $this->db->select('*')
->select_max('date')
->where('symbol',$symbol)
->get('company')
->row_array();
}
如何在单个查询中完成?
我认为您可以这样做:
if($symbol == ""){
$where = "symbol != 0"; ##$where = "symbol != ''"; whichever suits your case
}else{
$where = "symbol = '".$symbol."'";
}
$data_array = $this->db->select('*')
->select_max('date')
->where($where, false, false)
->get('company')
->row_array();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句