CodeIgniter Forums

Full Version: No Comparison in using Where()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

the following is the code i'm trying to execute:

public function lot_Count($firstfour)
    $this->db->where('SUBSTR(Lot_Number FROM 1 FOR 4)', $firstfour);
    $count = $this->db->count_all_results('Alfa_Order_Details');    

the proper argument that would be passed in would be "F21X", and when this is done, by having the MySQL server log everything, i've discovered CI is generating this SQL statment:

SELECT COUNT(*) AS `numrows` FROM (`Alfa_Order_Details`) WHERE SUBSTR(Lot_Number FROM 1 FOR 4) 'F21X'

There is no equality in the WHERE section, so the query fails... if i copy the query over to Phpmyadmin, and add the '=' it works fine! any ideas? Bug?

El Forum

$this->db->where('SUBSTR(Lot_Number FROM 1 FOR 4) =', $firstfour);