PHP MYSQL WHERE AND跟OR

WBOY
Release: 2016-10-17 09:30:18
Original
1736 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!