开发者

Search using LIKE Clause Mysql

开发者 https://www.devze.com 2023-01-15 00:29 出处:网络
I\'m tring to convert a Mysql query to using a LIKE clause and I can\'t make it work. $query = \"SELECT id,name FROM `hin` WHERE name = \'\".$q.\"\'\";

I'm tring to convert a Mysql query to using a LIKE clause and I can't make it work.

$query = "SELECT id,name FROM `hin` WHERE name = '".$q."'";

What I've tried in some variatio开发者_如何学运维ns.

$query = "SELECT id,name FROM `hin` WHERE name LIKE %'".$q."'%";

I need the query to select row only on string match. Intend is to use variable as needle.


Use:

"SELECT id,name FROM `hin` WHERE name LIKE '%". $q ."%'"

The wildcarding has to be inside the single quotes.

Ideally, you want to use:

"SELECT id,name FROM `hin` WHERE name LIKE '%". mysql_real_escape_string($q) ."%'"
0

精彩评论

暂无评论...
验证码 换一张
取 消