How do I nest queries for different conditions in MySQL thinkphp?

Source: Internet
Author: User
1 For example, I want to price in 20-30 50-60 70-80 price range of goods, the relationship is or
2 at the same time, the title should include skirts, tops, coats, or
3 also exclude the title contains children's wear, books, relations for and,
3 result merges are sorted by ID and then the data is fetched.

Probably similar to the following MySQL statement
(Price range 1 or price range 2 or price range 3) and (Heading 1 or Heading 2 or Heading 3) and (title not in (...)) Order by ID

And then thinkphp how to use his chain operation to express, especially inside the complex nested query conditions? Or what kind of approach is generally used?

Reply content:

1 For example, I want to price in 20-30 50-60 70-80 price range of goods, the relationship is or
2 at the same time, the title should include skirts, tops, coats, or
3 also exclude the title contains children's wear, books, relations for and,
3 result merges are sorted by ID and then the data is fetched.

Probably similar to the following MySQL statement
(Price range 1 or price range 2 or price range 3) and (Heading 1 or Heading 2 or Heading 3) and (title not in (...)) Order by ID

And then thinkphp how to use his chain operation to express, especially inside the complex nested query conditions? Or what kind of approach is generally used?

thinkphp where () is very useful, can be passed the form of the array of conditions, object form, can also be multiple parameters together, you can also accept the native SQL where part of the statement. That is, where (' (Price range 1 or price range 2 or price range 3) and (Heading 1 or Heading 2 or Heading 3) and (title not in (...)) ') so it is possible, if this can not meet you, you can complete the $this->quer Y () [M (' XXX ')->query ()] to execute a native SQL

What you need is a combination query in thinkphp.

_string _logic _complex These kinds of usage 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.