CodeIgniter Forums
No Comparison in using Where() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter Archived (from EllisLab) (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: No Comparison in using Where() (/thread-42957.html)



No Comparison in using Where() - El Forum - 06-24-2011

[eluser]kb1ibh[/eluser]
the following is the code i'm trying to execute:

Code:
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:

Code:
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?


No Comparison in using Where() - El Forum - 06-24-2011

[eluser]danmontgomery[/eluser]
Code:
$this->db->where('SUBSTR(Lot_Number FROM 1 FOR 4) =', $firstfour);