thinkphp uses native query to implement Association query left join instance, Thinkphpjoin
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.
http://www.bkjia.com/PHPjc/920614.html www.bkjia.com true http://www.bkjia.com/PHPjc/920614.html techarticle thinkphp uses the native query to implement the association query left join instance, Thinkphpjoin This example describes the thinkphp using native query to implement the association query the left join method. Share to everyone ...