ThingEngineer / PHP-MySQLi-Database-Class

Wrapper for a PHP MySQL class, which utilizes MySQLi and prepared statements.
Other
3.3k stars 1.34k forks source link

Query with mixed Where clause #737

Open momoelz opened 6 years ago

momoelz commented 6 years ago

I have a little problem, maybe I dont know how it use coded correctly.

The Case is following, i have a Table for messages with sender & reciever which can vary depending on who sends to whom the message lets say there is a conversation between A & B

so sender can be A & B and reciever can be A & B

right now i use this code but it only shows me messages from A

        $messages = messages::ArrayBuilder()
                    ->where('receiver',$receiver)
                    ->orWhere('sender',$sender)
                    ->where('sender',$sender)
                    ->orWhere('receiver',$receiver)
                    ->where('status',0)
                    ->orderby('timestamp','DESC')
                    ->paginate($page);
jeffstagedoor commented 6 years ago

wouldn't it be easier to do

->where ('receiver', array($receiver, $sender), 'IN')
->orWhere('sender', array($receiver, $sender, 'IN')
siberfx commented 6 years ago

->where ('receiver', array($receiver, $sender), 'IN') ->orWhere('sender', array($receiver, $sender), 'IN')

momoelz commented 6 years ago

thx the working querry is

->where ('receiver', array($receiver, $sender), 'IN') ->Where('sender', array($receiver, $sender, 'IN')

elzahaby commented 4 years ago

Any idea on how to create queries with conditions in Round Brackets? where you could do something like this::

... WHERE ... AND (column1 = X OR (column2 = 0 AND column3 > X))