使用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);
thinkphp left join关联查询
原文:http://www.cnblogs.com/panqingqiang/p/4271169.html