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.