MySql LIKE无法正常工作

时间:2016-11-19 11:54:37

标签: php mysql

当我搜索'新德里'时不工作但是当我搜索诺伊达时,它工作正常。当String有空格时如何使用LIKE。

$area = $_REQUEST('area');
$sql = "SELECT * from Student_registration WHERE area LIKE %".$area."%";

2 个答案:

答案 0 :(得分:3)

搜索条件周围缺少引号

"SELECT * from Student_registration WHERE area LIKE '%". $area."%'";

"SELECT * from Student_registration WHERE area LIKE concat('%', '" .$area. ",'%'";

答案 1 :(得分:2)

您缺少围绕字符串的单引号:

$sql = "SELECT * from Student_registration WHERE area LIKE '%".$area."%'";