我必须执行查询检查变量是否为空。像:
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();
}
如何在单个查询中创建它?
答案 0 :(得分:2)
我认为你可以这样做:
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();