-1

我想用多个输入搜索记录。如果我在文本字段记录中输入像德里、孟买这样的关键字,应该显示

my code is
<input type="search" name="search[]">
$location=$_POST['search'];
mysql_query("select * from record where location like '%$location%'")

请帮助我,我无法搜索多个位置的记录

4

1 回答 1

0
  1. 请改用 mysqli 或 PDO。
  2. 我假设您有多个名为“search[]”的输入字段。

你应该做的是这样的:

$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);
于 2013-11-09T13:04:04.190 回答