使用SQL like运算符

时间:2012-11-21 12:16:28

标签: mysql select sql-like

由于某种原因,我无法让这个SQL查询工作。我能做错什么?我是否正确连接?

$search_query= "SELECT * FROM users WHERE lname LIKE %'".$search_term."'%"

6 个答案:

答案 0 :(得分:6)

将代码重写为:

$search_query= "SELECT * FROM users WHERE lname LIKE '%".$search_term."%'"

答案 1 :(得分:4)

$search_query = "SELECT * FROM users WHERE lname LIKE '%".$search_term."%'";

答案 2 :(得分:3)

您将%放在单引号之外。

$search_query= "SELECT * FROM users WHERE lname LIKE '%".$search_term."%'";

答案 3 :(得分:3)

您应该将百分比字符放在引号内:

$search_query= "SELECT * FROM users WHERE lname LIKE '%".$search_term."%'"

答案 4 :(得分:1)

 $search_query= "SELECT * FROM users
                 WHERE lname LIKE '%".$string."%'";

答案 5 :(得分:0)

查看差异

%' '%

$ search_query =“SELECT * FROM users WHERE lname LIKE'%”。$ search_term。“%'”;