简体   繁体   English

从PHP中的多个表搜索

[英]Search from multiple table in php

I have a site in which I want to allow the users to search as multiple keyword as a string. 我有一个网站,我希望允许用户以多个关键字作为字符串进行搜索。 Suppose I have 3 tables: Subject , Level and users . 假设我有3个表: SubjectLevelusers If user search for Primary Computer Science Male Test , I Want to show the results from joining three tables. 如果用户搜索Primary Computer Science Male Test ,我想显示连接三个表的结果。 That is Primary from table Level and computer Science from table Subjects and remaining from the user table. 这是表Level Primary ,表Subjects computer Science ,而user表则是computer Science If the user search for computer science just show the results from table Subject . 如果用户搜索computer science仅显示表Subject的结果。 How it possible using MYSQL query? 如何使用MYSQL查询?

User input: 用户输入:

Computer Primary

Compose Query in this way: 以这种方式编写查询:

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 

Where :firsterm is the first user input term and :secondterm is the scond once 其中:firsterm是第一个用户输入词,而:secondterm是秒

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM