简体   繁体   English

php mysql 查询问题

[英]php mysql query issue

here's my table:这是我的桌子:

在此处输入图像描述

and I want get the customers which have some values of for/category fields which is comma separated..并且我希望获得具有逗号分隔的for/category字段的某些值的客户..

I am trying something like this:我正在尝试这样的事情:

SELECT * FROM `customers` WHERE `for` LIKE ('%AMC PHD & WWS%' OR '%Rostfrei%' OR '%Thermopac%')

but its giving empty result.但它给出了空的结果。

RedFilter's SQL is correct, but you should also know that "for" is a MySQL reserved word. RedFilter 的 SQL 是正确的,但你也应该知道“for”是一个 MySQL 保留字。 You should avoid using it as a column name, or wrap it in backticks when you use it:您应该避免将其用作列名,或者在使用时将其包装在反引号中:

SELECT * 
FROM customers 
WHERE `for` LIKE '%AMC PHD & WWS%'
    OR `for` LIKE '%Rostfrei%'
    OR `for` LIKE '%Thermopac%';

The alternative, typing the column name once is:另一种方法是输入一次列名:

SELECT * FROM customers WHERE `for` REGEXP 'AMC PHD \& WWS|Rostfrei|Thermopac';

Try:尝试:

SELECT * 
FROM customers 
WHERE for LIKE '%AMC PHD & WWS%'
    or for LIKE '%Rostfrei%'
    or for LIKE '%Thermopac%'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM