In thinkphp, how does mysql nest query different conditions?

Source: Internet
Author: User
1. For example, if I want products with prices in the price range of 20-3050-6070-80, the relationship is or2, and the title should contain skirts, jackets, and coats. 3. I also want to exclude titles including children's clothes and books, the relationship is and, and the three results are merged and sorted by IDs, and then the data is retrieved. probably similar to the following mysql Statement (price... 1 For example, if I want a product with a price range of 20-30 50-60 70-80, the relation is or.
2 At the same time, the title should contain a skirt, coat, or coat,
3. Also exclude titles including children's clothes, books, and relationships,
The three results are merged and sorted by id, and then the data is retrieved.

Probably similar to the following mysql statement
(Price range 1 or price range 2 or price range 3) and (Title 1 or title 2 or Title 3) and (title not in (...) order by id

In thinkphp, how can I use his chained operation to express it, especially the complicated nested query conditions in it? Or what kind of method will be used in general?

Reply content:

1 For example, if I want a product with a price range of 20-30 50-60 70-80, the relation is or.
2 At the same time, the title should contain a skirt, coat, or coat,
3. Also exclude titles including children's clothes, books, and relationships,
The three results are merged and sorted by id, and then the data is retrieved.

Probably similar to the following mysql statement
(Price range 1 or price range 2 or price range 3) and (Title 1 or title 2 or Title 3) and (title not in (...) order by id

In thinkphp, how can I use his chained operation to express it, especially the complicated nested query conditions in it? Or what kind of method will be used in general?

Thinkphp's where () is very useful. It can be used to transmit the Form Conditions of arrays, object forms, multiple parameters, and some native SQL where statements. That is, where ('(price range 1 or price range 2 or price range 3) and (Title 1 or title 2 or Title 3) and (title not in (....)) ') You can use $ this-> query () [M ('xxx')-> query ()] to execute a native SQL statement.

What you need is the combined query in thinkphp

The usage of _ string _ logic _ complex can be satisfied.

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.