PHP combined query multi-condition query example code page 1/2_PHP tutorial

WBOY
Release: 2016-07-21 15:51:32
Original
886 people have browsed it

Let me first explain the requirements to you: According to the requirements of our system, we will perform combined queries through fields such as department name, employee name, PC name, IP address, etc. to obtain the desired data results. So, for the sake of simplicity, we use a combined query of two conditions (department name, employee name) to explain this technical technique to everyone. When we only enter the department name and the employee name is empty, all employee information in the department will be displayed. Only when you restrict the department and employee names at the same time can you query the unique information.

Then let’s get started.

First create the query page search.php. Different from the last single condition query, this time we need a combination of two conditions to query.



Query



Department name:


Employee name:



< /form>


Like last time, we pass the values ​​of part and ename to the search_result.php file through the Post method.

Then comes the key to this topic, how the search_result.php file accepts these two parameter values, and determines how to exclude it from the query conditions when one of the fields is empty.

How to understand the above sentence? For example, if we simply write the query statement to receive parameters as select * from info where department='department value parameter' and ename='employee name parameter' , then if one of the parameters is empty, we will get select * from info where department='Technical Department' and ename='' . Obviously, such a query is likely to return empty results, because the meaning of this query statement That is, querying the data of all unnamed people in the technical department. Isn't this ridiculous? On the other hand, if it is select * from info where department='' and ename='sunec', then it means querying the employee whose name is sunec but Naturally, there will be no query results for people who do not belong to any department.

The correct approach should be to filter out the null parameter in the query statement. For example, when we only enter the department name, we should get select * from info where department='Technical Department'. In this way, the meaning of the query statement becomes to query the information of employees in the technical department of all departments. This is what we want.

Once the idea is clear, then we will implement it next time!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319150.htmlTechArticleFirst explain the requirements to everyone: According to the requirements of our system, we will pass the department name, employee name, PC name, IP address and other fields to perform combined queries to get the desired data result...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!