Heim  >  Artikel  >  Backend-Entwicklung  >  ThinkPHP采用原生query实现关联查询left join实例_php实例

ThinkPHP采用原生query实现关联查询left join实例_php实例

WBOY
WBOYOriginal
2016-06-07 17:15:05930Durchsuche

本文实例讲述了ThinkPHP采用原生query实现关联查询left join的方法。分享给大家供大家参考。具体如下:

thinkphp提供了join方法来实现关联查询,但是很不好用,还是用原生的方便,所以推荐大家用query方法:

复制代码 代码如下:
$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);

 希望本文所述对大家的ThinkPHP框架程序设计有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn