Today, I want to introduce how to perform multi-condition combined query between PHP pages. There are also many related Introductions on many other websites, but they are not detailed enough. here, I will give you a detailed description of this practical but critical technology. First, describe the requirements. according to the requirements of our system, we will query the desired data by combining the department name, employee name, PC name, IP address, and other fields. For the sake of simplicity, we use a combination of two conditions (department name and employee name) to explain this technical skill. When we enter only the department name and the employee name is null, all employee information in the department will be displayed. only when you restrict both the department and employee names can you query the unique information.
Let's start.
First, the search. php query page is created. Unlike the previous single condition query, this query requires a combination of two conditions.
Like the previous one, we pass the value of depart and ename to the search_result.php file through the Post method.
Then the key of the topic is reached. how does the search_result.php file accept the two parameter values and determine how to exclude the query conditions when one field is null.
How to understand the above sentence, for example, if we simply write the query statement of the receiving parameter as select * from info where depart = 'Department value parameter' and ename = 'employee name parameter, if one of the parameters is null, we will get select * from info where depart = 'technical department 'and ename = ''. Obviously, such a query may return null results, this query statement is used to query the data of all persons without technical department names. isn't that ridiculous, if it is select * from info where depart = ''and ename = 'sunec ', it means to query the person whose employee name is sunec but does not belong to any department, naturally, no results can be found.
The correct method should be to filter out the null parameter in the query statement. For example, if we only enter the department name, we should get select * from info where depart = 'technical department '. In this way, the query statement means to query the information of all departments as technical department employees. this is what we want.
With a clear idea, we will implement it next time!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.