thinkphp join 查询
1 $model = M();
// 表名必须是完整的表名,如果有前缀,要加前缀 2 $count = $model->table('wx_wxusers_purview p')->join('wx_wxusers u on p.openId=u.openid')->where($joinWhere)->count(); 3 import('Org.Util.Page'); 4 $page = new Page($count, 10);
// 查询的字段需要使用表别名的使用表别名 5 $field = array('p.id', 'u.openid', 'u.headimgurl', 'u.nickname', 'u.province', 'u.city'); 6 $wxusers = $model->table('wx_wxusers_purview p')->join('wx_wxusers u on p.openId=u.openid')->field($field)->where($joinWhere)->limit($page->firstRow.','.$page->listRows)->select(); 7 $this->wxusers = $wxusers;
8 $this->page = $page->show();