简体   繁体   English

在 sql 查询中使用 Like 时不返回任何结果

[英]No results are returned when using Like in sql query

I am having syntax issue with MySQL with PHP.我在使用 PHP 时遇到了 MySQL 的语法问题。

My code:我的代码:

$q['item_desc LIKE \'%?%\'"'] = array($criteria);

but it gets translated to SQL Query:但它被转换为 SQL 查询:

SELECT `Item`.`id`, `Item`.`item_desc`, `Item`.`row_num`, `Item`.`shelf_num`, `Item`.`shelf_loc`, `Item`.`datetime` FROM `inventory`.`items` AS `Item` WHERE `item_desc` LIKE '%'10'%'"

I believe I need to get rid of the single quotes inside the % .我相信我需要去掉%中的单引号。 How do I do this?我该怎么做呢?

There is an un needed double quote in there.那里有一个不需要的双引号。

Try尝试

$q['item_desc LIKE \'%?%\'']

or或者

$q["item_desc LIKE '%?%'"]

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

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