thinkphp using native query to implement association queries left JOIN instance _php instance

Source: Internet
Author: User
The example in this paper describes the method of using native query to implement the left join of thinkphp query. Share to everyone for your reference. Specific as follows:

Thinkphp provides a join method to implement the associated query, but it is very difficult to use, or to use the native convenience, so we recommend that you use the Query method:
Copy the Code code as follows: $Model = new Model ();
$sql = "Select a.ID, A.attr_name, A.attr_input_type, A.attr_type, A.attr_values, V.attr_value, V.attr_price".
"From Hh_typeattr as a".
"Left JOIN hh_siteattr as V".
"On v.attr_id = a.id and v.site_id = ' $site _id '".
"WHERE a.type_id =". Intval ($type _id). " OR a.type_id = 0 ".
"ORDER by A.listorder, A.attr_type, a.ID, V.attr_price, v.id";
$row = $Model->query ($sql);

It is hoped that this article will be helpful to everyone's thinkphp framework design.

  • Related Article

    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.