![]() |
Active record help - 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: Active record help (/showthread.php?tid=32948) |
Active record help - El Forum - 08-10-2010 [eluser]bradleyg[/eluser] Been trying to work this out for a while... just can't get it. Search param 1 will either be an email or username. Search param 2 will be an array of regions (integers). Code: $param2 = array(2,3); I'm not very good with mysql so excuse the incorrect syntax. Code: select * from table where username = $param1 OR email = $param1 AND region = 2 OR region = 3; Any help? Thanks Active record help - El Forum - 08-10-2010 [eluser]WanWizard[/eluser] This AR code produces Code: WHERE region IN (2,3) AND username = $param1 OR email = $param2 You probably want Code: WHERE region IN (2,3) AND ( username = $param1 OR email = $param2 ) A dirty trick is Code: $param2 = array(2,3); Other solution Code: $this->db->where("(`username` = $param1 OR `email` = $param1)", NULL, FALSE); Active record help - El Forum - 08-19-2010 [eluser]far032[/eluser] [quote author="WanWizard" date="1281487799"]This AR code produces Code: WHERE region IN (2,3) AND username = $param1 OR email = $param2 You probably want Code: WHERE region IN (2,3) AND ( username = $param1 OR email = $param2 ) A dirty trick is Code: $param2 = array(2,3); Other solution Code: $this->db->where("(`username` = $param1 OR `email` = $param1)", NULL, FALSE); nice!!!!!! Thanks a lot. Active record help - El Forum - 08-19-2010 [eluser]bradleyg[/eluser] [quote author="WanWizard" date="1281487799"]This AR code produces Code: WHERE region IN (2,3) AND username = $param1 OR email = $param2 You probably want Code: WHERE region IN (2,3) AND ( username = $param1 OR email = $param2 ) A dirty trick is Code: $param2 = array(2,3); Other solution Code: $this->db->where("(`username` = $param1 OR `email` = $param1)", NULL, FALSE); Perfect, thanks. I think I will go for the 2nd option. Cheers! |