Sichuan Media College 2014 years of artistic achievement query PHP combination query multi-conditional query Instance code 1th/2 page

Source: Internet
Author: User
First of all to explain the needs: according to our system requirements, we will be the department name, employee name, PC name, IP address and other fields to make the combined query to obtain the desired data results. So, for the sake of simplicity, we use a combination of two criteria (department name, 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 presented and only when you restrict the name of the department and employee can you query the unique information.
Then let's start.
First set up a query page search.php, different from the last single-condition query, this time we need two conditions of the combination of query.


Inquire





As we did last time, we pass the value of depart and ename to the search_result.php file through the Post method.
Then came the key to this topic, how the search_result.php file accepts both parameter values, and determines how the query condition is excluded when one of the fields is a null value.
How to understand the above sentence, for example, if we simply write the query statement that receives the parameter into the select * from info where depart= ' department value parameter ' and ename= ' employee Name parameter ', then if one of the arguments is empty we will get SELECT * FROM info where depart= ' technical department ' and Ename= ', obviously, such a query is likely to return an empty result, because this query statement means to query all technical departments without name of the data, it is not very absurd, upside down if it is SELECT * FROM info where depart= ' and ename= ' Sunec ', then it means querying employees whose names are sunec but not belonging to any department, which is naturally also not the result of the query.
The correct approach should be to filter out the null-valued argument in the query statement. For example, we should get a select * from info where depart= ' technical department ' when we enter only the department name. In this way, the meaning of the query will become a query of 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 page

The above introduces the Sichuan Media College 2014 years of artistic achievements query PHP combination query multi-conditional query Instance code 1th/2 page, including the Sichuan Media College 2014 years of Art grade query content, I hope that the PHP tutorial interested friends have helped.

  • 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.