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.