如何通过三个包含多个搜索词的表格使用sql和php进行良好的搜索?以及如何在屏幕上回馈它?
我在我的实习中自制的框架中工作。以下我捏造自己只是这个我认为不完全正确。
我有以下想法准备好了:
function find_by_all($search) {
$searchwords = explode(" ", $search);
foreach ($searchwords as $word) {
if ($word === end($searchwords)) {
$query_where .= "companies.companyname LIKE '%" . $word . "%' OR companies.city LIKE '%" . $word . "%' OR persons.firstname LIKE '%" . $word . "%' OR persons.lastname LIKE '%" . $word . "%' OR investments.name LIKE '%" . $word . "%' OR investments.firstname LIKE '%" . $word . "%' OR investments.lastname LIKE '%" . $word . "%'";
} else {
$query_where .= "companies.companyname LIKE '%" . $word . "%' OR companies.city LIKE '%" . $word . "%' OR persons.firstname LIKE '%" . $word . "%' OR persons.lastname LIKE '%" . $word . "%' OR investments.name LIKE '%" . $word . "%' OR investments.firstname LIKE '%" . $word . "%' OR investments.lastname LIKE '%" . $word . "%' AND ";
}
}
return $this->find_by_sql("SELECT * FROM companies LEFT JOIN investings ON investings.investing_id = companies.company_id LEFT JOIN investments ON investments.investment_id = companies.company_id LEFT JOIN persons ON persons.person_id = companies.company_id WHERE ".$query_where);
现在我认为这个相当不错,只有这个SQL和结果我还需要在屏幕上看到,只是我不知道如何做到这一点。任何人都可以帮助我吗?
答案 0 :(得分:0)
我做到了,现在不再需要帮助我了。我为搜索功能做了三个单独的查询,现在他就这样做了。