Home > Article > Backend Development > PHP MYSQL WHERE AND跟OR
I would like to ask how to set the where condition
<code>WHERE `status` = '已完成' AND `type` = '' AND `phone` LIKE '%{$user}%' OR `phone2` LIKE '%{$user}%' OR `address` LIKE '%{$user}%' OR `name` LIKE '%{$user}%' OR `email` LIKE '%{$user}%' ORDER BY `buytime` DESC </code>
The condition is "status must be completed and type must be empty"
Then any other matching one is fine
If I do this, it will become status if it is not completed. If type is not empty, it will also be searched
I would like to ask how to set the where condition
<code>WHERE `status` = '已完成' AND `type` = '' AND `phone` LIKE '%{$user}%' OR `phone2` LIKE '%{$user}%' OR `address` LIKE '%{$user}%' OR `name` LIKE '%{$user}%' OR `email` LIKE '%{$user}%' ORDER BY `buytime` DESC </code>
The condition is "status must be completed and type must be empty"
Then any other matching one is fine
If I do this, it will become status if it is not completed. If type is not empty, it will also be searched
<code class="sql">WHERE `status` = '已完成' AND `type` = '' and ( `phone` LIKE '%{$user}%' or`phone2` LIKE '%{$user}%' OR `address` LIKE '%{$user}%' OR `name` LIKE '%{$user}%' OR `email` LIKE '%{$user}%' ) ORDER BY `buytime` DESC</code>