Javascript-php multi-condition filter Query

Source: Internet
Author: User
Just like this, how to do multi-condition search?

Just like this, how to do multi-condition search?

Reply content:

Just like this, how to do multi-condition search?

Directly run the Code:

$ Query = []; $ valid = ['type', 'area ', 'Year', 'person']; // valid query Key: type/region/age/star foreach ($ _ get as $ queryName) {// when querying all, ignore this condition if ($ _ GET [$ queryName]! = 'All') & in_array ($ queryName, $ valid) {$ query [$ queryName] =_ _ GET [$ queryName];} $ where = count ($ query )? 'Where'. implode (',', $ query): ''; $ result = $ db-> query (" SELECT * FROM tableName {$ WHERE }");

These conditions are a classification.
The intersection under various categories is good.
Use the where statement in mysql and connect with and.

Concatenate SQL statements. Set an array $ search to save the submitted condition values. For example, $ search ['type'] = $ _ GET ['type'] assigns each condition a value once. Before splicing an SQL statement, you must determine each condition, for example, if ($ search ['type']) $ query. = 'AND type =? '; $ Bind [] = $ search ['type'];
Concatenate SQL statements when the conditions are not empty. Otherwise, the SQL statements are not concatenated.

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.