2014-01-18 66 views
0

我有一個網站,我想讓用戶搜索多個關鍵字作爲字符串。 假設我有3個表格:Subject,Levelusers。如果用戶搜索Primary Computer Science Male Test, 我想顯示加入三個表格的結果。這是表Levelcomputer Science中的Primary,其來自表Subjects,剩餘的來自user表。如果用戶搜索computer science只顯示錶Subject的結果。如何使用MYSQL查詢?從多個表中搜索在php

+0

我認爲這是自然語言處理領域。我對此沒有廣泛的瞭解。 – ariefbayu

回答

0

用戶輸入:

Computer Primary 

撰寫查詢這樣:

select * 
from Subject as s join level as l on s.id = l.subject_id 
    join users as u on u.subject_id = s.id 
where 
    l.name = :firstterm or s.name = :firstterm or u.name = :firsterm or 
    l.name = :secondterm or s.name = :secondterm or u.name = :secondterm 

其中:firsterm是第一個用戶輸入項和:secondterm是scond一次