thinkphp left join关联查询

作者: 小新新2015
发布时间:2015-06-29 17:44:35

使用sql查询:
SELECT a.*,b.gs_schoolnamecn,b.gs_schoolnameen FROM tsh_greenaction a  LEFT JOIN tsh_greenschool b on a.greenschoolid=b.id 

 

  使用thinkphp连贯操作:

     $model=M('greenaction');
     $list=$model->alias('a')->join(' LEFT JOIN tsh_greenschool b on a.greenschoolid=b.id')
     ->field('a.*,b.gs_schoolnamecn,b.gs_schoolnameen')->select();
     $temp='';
  for($i=0;$i<count($list);$i++){
  $temp=$temp.$list[$i]['gs_schoolnamecn'].',';
  }

       dump($temp); 

标签: php thinkphp
来源:http://www.cnblogs.com/panqingqiang/p/4271169.html

推荐: