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\'
You Can also Pass a String parameter to where() function like this,
$this->db->where('product_stocks.stock_level > 1');
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
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.
I think this should do the trick:
$this->db->where('product_stocks.stock_level >', '1'); //moved the >