我想用多个输入搜索记录。如果我在文本字段中输入像delhi,mumbai这样的关键字 记录应显示
my code is
<input type="search" name="search[]">
$location=$_POST['search'];
mysql_query("select * from record where location like '%$location%'")
请帮助我,我无法搜索多个位置的记录
答案 0 :(得分:0)
你应该做的是这样的事情:
$locations=$_POST['search'];
$likeSqlStr = '';
foreach ($locations as $loc) {
if (!empty($loc)) {
$likeSqlStr .= " OR location LIKE '%" . $loc . "%'";
}
}
$query = "select * from record where (" . (!empty($likeSqlStr) ? '0' . $likeSqlStr : '1') . ")";
$results = mysqli_query($query);