我一直在阅读评论和你的问题,我认为你需要一点 PHP 来准备你的 MySql 语句,以及一个 Mysql 查询来获取限制在前 5 个没有重复项的匹配结果?
如果是这样!!
PHP
<?php
$searchFieldData = $_POST['search'];
$searchArr = explode(" ", $searchFieldData);
$sqlWhere = '';
$count = count($searchArr);
foreach ($searchArr as $or) {
$sqlWhere.= " title LIKE '%".$or."%' ";
if ($count>1) $sqlWhere.= " OR ";
$count--;
}
$query = "SELECT col1, col2, ... FROM table WHERE ".$sqlWhere." LIMIT 5";
?>
上面的代码将返回搜索词: “超级超级查询爬虫”
SELECT col1, col2, ... FROM table WHERE title LIKE '%super%' OR title LIKE '%hyper%' OR title LIKE '%query%' OR title LIKE '%crawler%' LIMIT 5
现在为 MYSQL 魔法
如果您不想要任何重复的结果,只需使用:GROUP BY 'title'
您的最终查询将是:
$query = "SELECT col1, col2, ... FROM table WHERE ".$sqlWhere." GROUP BY 'title' LIMIT 5";