PHP combination Query multi-condition query Instance code 1th/2 page _php Basics

Source: Internet
Author: User

First of all to explain the requirements: according to our system requirements, we will be through the department name, employee name, PC name, IP address and so on fields to make a combination of queries to get the desired data results. So, for the sake of simplicity, we use a combination of two conditions (department name, employee name) to explain the technical skills. When we enter only the department name and the employee's name is NULL, all employee information in the department will be rendered, and only information can be queried if you restrict both the department and the employee's name.

So let's start.

First set up a query page search.php, different from the last single condition query, this time we need two combinations of conditions to query.

<body>
<form action= "search_result.php" method= "POST" >
Department Name: <input type= "text" size=25 name= "Depart" value= "" > <br><br>
Employee Name: <input type= "text" size=25 name= "ename" value= "" > <br><br>
<input type= "Submit" Name= "submitted" value= "Submit" >
</form>
</body>
As we did last time, we passed the value of depart and ename to the search_result.php file via the Post method.

Then came the key to this topic, how the search_result.php file accepts these two parameter values, and determines how to exclude the query criteria when one of the fields is null.

How to understand the above sentence, for example, if we simply write the query statement that receives the parameter as a select * from info where depart= ' departmental value parameter ' and ename= ' employee Name parameter ', then if one of the arguments is empty we will get SE Lect * from info where depart= ' technical department ' and Ename= ', obviously, such a query is likely to return empty results, because this query means that query all the technical department has no name of the person's data, this is not absurd, if the upside is SELECT * FROM info where depart= ' and ename= ' Sunec ', then it means to query the employee whose name is Sunec but does not belong to any department, that nature is not the result of the query.

The correct way to do this is to filter out the null-valued parameter in the query statement. For example, when we just type in the department name we should get select * from info where depart= ' technology department '. In this way, the meaning of the query is to query all departments for the technical staff of the information, which is what we want.

Clear the idea, then, next time we will go to achieve it!

Current 1/2 page 12 Next read the full text

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.