複数の検索語を含む 3 つのテーブルで 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 と結果だけを画面に表示する必要がありますが、これを行う方法がわかりません。誰でも私を助けることができますか?