代码点火器多个where子句不起作用

时间:2016-04-05 06:31:52

标签: php codeigniter

代码点火器模型在页面加载性别= 3时返回json_encode结果,如果单击女性按钮性别= 1并且单击男性按钮性别= 2。现在我想在if条件旁边添加另一个where语句。如果条件,请参见性别= 3。



function get_data_all($gender, $age_min, $age_max) { 
        
        $counter = 0;             
        $this->db->select('*');             
        if($gender == 1){ 
            $this->db->where('gender', 'F'); //working 
            $counter++;
        }
        elseif($gender == 2){
            $this->db->where('gender', 'M');  //working                        
            $counter++;
        }
        elseif($gender == 3){                   
            $names = array('F', 'M');              
            $this->db->where_in('gender', $names);   //working 
            $this->db->where('age>=', 12);  //not working
            $this->db->where('age<=', 18);  //not working               
            $counter++;
        }
        else{
            redirect(base_url());
        }                    
        $query = $this->db->get('sudent_details');               
        if (($query->num_rows() > 0) && ($counter > 0)){                
            echo(json_encode($query->result()));                          
            $counter = 0;                            
        } else {                
            return false;
        }
    }
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:3)

在列名称中添加空格&amp;比较运算符

$this->db->where('age >= ', 12);
$this->db->where('age <= ', 18);

答案 1 :(得分:2)

您需要替换以下行:

$this->db->where('age>=', 12);  //not working
$this->db->where('age<=', 18);  //not working  

$this->db->where('age','>=',12);  
$this->db->where('age','<=',18);

$this->db->where('age >= 12',FASLE,FALSE);  
$this->db->where('age <= 18',FASLE,FALSE);

$this->db->where('age>=', 12,FALSE);
$this->db->where('age<=', 18,FALSE);

它应该有用。