ThinkPHP uses native query to implement associated query left join example, thinkphpjoin_PHP tutorial

WBOY
Release: 2016-07-13 10:12:34
Original
782 people have browsed it

ThinkPHP uses native query to implement associated query left join instance, thinkphpjoin

The example in this article describes the method of ThinkPHP using native query to implement left join of associated query. Share it with everyone for your reference. The details are as follows:

thinkphp provides the join method to implement related queries, but it is very difficult to use. It is more convenient to use the native method, so it is recommended that you use the query method:

Copy code 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 a ". "FROM hh_typeattr AS a ".
"LEFT JOIN hh_siteattr AS v ". "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 be helpful to everyone’s ThinkPHP framework programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/920614.htmlTechArticleThinkPHP uses native query to implement associated query left join example, thinkphpjoin This article tells the example of ThinkPHP using native query to implement associated query left join method. Share it with everyone for everyone...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!