以下是我的代码
$state = $data['state'];
$this->db->select("state")->from('table')
->where('en_movingfrom_state', $state)
->where('status', 3);
如果设置了$state
,那么我想执行此查询,然后执行条件。
所以,请帮助我,我该怎么做?
答案 0 :(得分:1)
试试这个:
$state = $data['state'];
// checking `$state has set`
if (isset($state) && (trim($state) != '')) {
$this->db->where('en_movingfrom_state', $state)
}
$result = $this->db->select("state")->from('table')
->where('status', 3)
->get()->result_array();
// Output
print_r($result);
答案 1 :(得分:0)
你可以使用isset()函数来检查是否设置了$ state
$state = $data['state'];
$this->db->select("state")->from('table');
if(isset($state) && $state != ""){
$this->db->where('en_movingfrom_state', $state);
}
$this->db->where('status', 3);
$this->db->get()->result_array();