Codeigniter Active record: greater than statement

后端 未结 4 1339
灰色年华
灰色年华 2021-01-07 23:25

I\'m trying to convert a \"greater than\" where statement to CI\'s Active Record syntax. When I use this snippet

    $this->db->join(\'product_stocks\'         


        
相关标签:
4条回答
  • 2021-01-07 23:44

    You Can also Pass a String parameter to where() function like this,

    $this->db->where('product_stocks.stock_level > 1');
    
    0 讨论(0)
  • 2021-01-07 23:46

    I would like to have in CI the following:

     $sQuery = "SELECT auftrag, saal, DATE_FORMAT(konzertdatum,'%e, %M, %Y') AS konzertdatum2 FROM auftrag 
        JOIN saal on auftrag.saal_id = saal.id 
        WHERE konzertdatum < NOW() + INTERVAL 240 DAY AND auftrag like '%$sWord%' order by konzertdatum asc LIMIT 4";
     $aOrder = $this->db->query($sQuery);
     $aOrder = $aOrder->result();
    

    It works fine without CI, but when I use

          $this->db->select("auftrag, saal, DATE_FORMAT(konzertdatum,'%e, %M, %Y') AS konzertdatum2", false );
        $this->db->from('auftrag');
        $this->db->join('saal', 'auftrag.saal_id = saal.id');
        $this->db->like('auftrag', $sWord);
        $this->db->where('konzertdatum <', 'NOW() + Interval 240 day');
    
        $this->db->order_by('konzertdatum');
        $this->db->limit(4);
    
        $oQuery = $this->db->get();
    
        $aOrder = $oQuery->result();
        print_r($this->db->last_query());
    

    it returns all results not caring about the where (although the sql seems fine):

    SELECT auftrag, saal, DATE_FORMAT(konzertdatum, '%e, %M, %Y') AS konzertdatum2 FROM (`auftrag`) JOIN `saal` ON `auftrag`.`saal_id` = `saal`.`id` WHERE `konzertdatum` < 'NOW() + Interval 240 day' AND `auftrag` LIKE '%spangenberg%' ORDER BY `konzertdatum` LIMIT 4 
    
    0 讨论(0)
  • 2021-01-07 23:49

    Either

    $this->db->where('product_stocks.stock_level >', '1');
    or
    $this->db->where(array('product_stocks.stock_level >'=>'1'));
    should do it. Note the space between the field name and the operator; otherwise you will end up getting Error 1064.

    0 讨论(0)
  • 2021-01-08 00:00

    I think this should do the trick:

    $this->db->where('product_stocks.stock_level >', '1');  //moved the >
    
    0 讨论(0)
提交回复
热议问题