Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Sql
#1

[eluser]Unknown[/eluser]
Hello I have a question with the sql with codeigniter.

I want to do this type of things :
( it is not syntaxe sql I know )
WHERE ( a = b AND c = d ) OR ( a = d AND c = b )

For do this I do :
$array = array( a => b, c => d);
$array2 = array(a => d, c => b);

// the rest of my code is ok with the database.
$db_default->where($array);
$db_default->or_where($array2);

When I do that the first part of array2 is ignored ( a => d ) and all the rest work.

Do you have a idea?
#2

[eluser]CroNiX[/eluser]
Current version of CI doesn't have a way to do compound wheres. CI3 will. But, you'd just have to enter that using a single where statement and write it manually for now.

Code:
$this->db->where('( a = b AND c = d ) OR ( a = d AND c = b )');
#3

[eluser]Unknown[/eluser]
It work thanks :

I put my code here if somebody have the same question :

Code:
$db_default->where('( id_transmitter = '.$_SESSION['id'].' AND id_receiver = '.$currentUser.' ) OR ( id_transmitter = '.$currentUser.' AND id_receiver = '.$_SESSION['id'].')');
#4

[eluser]sevengraff[/eluser]
So in this situation, you need to call $this->db->escape() manually?




Theme © iAndrew 2016 - Forum software by © MyBB