ThinkPHP uses native query to implement join query for leftjoin instances

Source: Internet
Author: User
This article mainly introduces ThinkPHP's method of using native query to implement join query leftjoin. The example shows how to use the query method in ThinkPHP, for more information, see the example in this article. ThinkPHP uses native query to implement join query left join. Share it with you for your reference. The details are as follows:

Thinkphp provides the join method to implement join queries, but it is not easy to use. it is still convenient to use native. Therefore, we recommend that you use the query method:

The code is 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 ".
"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 );

I hope this article will help you with ThinkPHP framework programming.

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.