Welcome Guest, Not a member yet? Register   Sign In
Active record help
#2

[eluser]WanWizard[/eluser]
This AR code produces
Code:
WHERE region IN (2,3) AND username = $param1 OR email = $param2
As there are no brackets in this where clause, it will be true if there is a region and a username match, or an email match.

You probably want
Code:
WHERE region IN (2,3) AND ( username = $param1 OR email = $param2 )
which you can't do with standard AR calls.

A dirty trick is
Code:
$param2 = array(2,3);
$this->db->where_in('region', $param2);
$this->CI->db->where('( 1 =', '1', false); // add a bracket open
$this->db->where('username', $param1);
$this->db->or_where('email', $param1);
$this->CI->db->where('1', '1 )', false); // add a backet close

Other solution
Code:
$this->db->where("(`username` = $param1 OR `email` = $param1)", NULL, FALSE);
but make sure $param1 is properly escaped.


Messages In This Thread
Active record help - by El Forum - 08-10-2010, 11:22 AM
Active record help - by El Forum - 08-10-2010, 01:49 PM
Active record help - by El Forum - 08-19-2010, 02:09 AM
Active record help - by El Forum - 08-19-2010, 02:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB