dtc4547 2016-04-05 06:31
浏览 43
已采纳

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

Code igniter model returns json_encode results when page load gender=3, if click female button gender=1 and if click male button gender=2. Now i want to add another where statements in side the if conditions. see when gender=3 if condition.

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;
        }
    }

</div>
  • 写回答

2条回答 默认 最新

  • dsfw2154 2016-04-05 06:56
    关注

    Add space in your column name & Comparison operator

    $this->db->where('age >= ', 12);
    $this->db->where('age <= ', 18);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 STM32L431RCT6 定时器2中断发起ADC 采样问题
  • ¥15 如何通过交互分析得出某高危患者对放疗获益更多
  • ¥15 相关性分析中,p<0.05, r=0.29,怎么评价相关性呢
  • ¥15 docker部署Mongodb后输入命令报错?
  • ¥15 将下列流程图转变成python程序代码
  • ¥15 我需要全国每个城市的最新小区名字等数据。
  • ¥15 开发一个小区生态的小程序
  • ¥15 如何解决Excel中dependent dropdown list 的问题
  • ¥15 MddBootstrapInitialize2失败
  • ¥15 LCD Flicker