![]() |
Rearrange active record querys? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Rearrange active record querys? (/showthread.php?tid=21565) |
Rearrange active record querys? - El Forum - 08-13-2009 [eluser]skylerrichter[/eluser] I have a query I am trying to do with the active records class but I am getting some unexpected results here is the model: Code: $this->db->select('id, first_name, last_name, email, status, industry'); Here is the result of the query (close but no cigar) : Code: SELECT `id`, `first_name`, `last_name`, `email`, `status`, `industry` FROM (`users`) WHERE `status` = 1 AND `id` IN ('66', '41') AND `first_name` LIKE '%a%' OR `last_name` LIKE '%a%' The LIKE statement needs to appear in brackets (`first_name` LIKE '%a%' OR `last_name` LIKE '%a%') And the WHERE IN statement needs to appear last in order to get the expected results IN ('66', '41') Ideally the correct SQL should look like this: Code: SELECT `id`, `first_name`, `last_name`, `email`, `status`, `industry` FROM (`users`) WHERE `status` = 1 AND ( `first_name` LIKE '%a%' OR `last_name` LIKE '%a%') AND `id` IN ('66', '41') Any ideas? Rearrange active record querys? - El Forum - 08-13-2009 [eluser]wabu[/eluser] How about just writing a custom where clause (still supported by where(), see docs)? |