Home > Backend Development > PHP Tutorial > Sichuan University of Communication 2014 Art Score Query PHP Combination Query Multi-Condition Query Example Code Page 1/2

Sichuan University of Communication 2014 Art Score Query PHP Combination Query Multi-Condition Query Example Code Page 1/2

WBOY
Release: 2016-07-29 08:38:10
Original
1130 people have browsed it

Let me first explain the requirements to you: According to the requirements of our system, we will use the department name, employee name, PC name, IP address and other fields to perform combined queries to get 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 the unique information be queried.
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: < ;br>





And last time Similarly, we pass the values ​​of part and ename to the search_result.php file through the Post method.
Then we come to the key point of 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 that receives parameters as select * from info where department='department value parameter' and ename='employee name parameter', then if one of them When the parameter 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 is to query all technologies Isn’t it ridiculous to select data about people without names in the department? On the other hand, if it is select * from info where department='' and ename='sunec', then it means to query the employees whose name is sunec but does not belong to any department. Man, naturally there is no result.
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!

Current page 1/2 12Next page

The above introduces the Sichuan University of Communication 2014 Art Score Inquiry PHP Combination Query Multi-Condition Query Example Code Page 1/2, including the content of the Sichuan University of Communication 2014 Art Score Inquiry, I hope friends who are interested in PHP tutorials Helps.

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