ThinkPHP uses native query to implement join query for left join instances and thinkphpjoin
This example describes how 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:
Copy codeThe 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.