Home  >  Article  >  Backend Development  >  PHP MYSQL WHERE AND跟OR

PHP MYSQL WHERE AND跟OR

WBOY
WBOYOriginal
2016-10-17 09:30:181736browse

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

Reply content:

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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn