tp5 之mysql关联查询

日期:2019-01-05 浏览:499次

1
2
3
4
5
6
7
8
Db::name('signs_statistics')
->alias('s')
->Join('sup_fans u','u.appid=s.appid and u.openid=s.openid')
->field('s.*,u.headimgurl as img')
->where('s.appid','eq',USER_APPID)
->limit(intval($post['start']), intval($post['length']))
->order('count_points DESC')
->select();
eg: 1、> 是'>',被转义了 2、关联表条件在join进行写明, 3、主表在外单独where 升级版
1
2
3
4
5
6
7
8
9
10
$data = Db::name('signs_record')
    ->alias('s')
    ->join('coupon c','c.card_id=s.card_id','LEFT')
    ->join('goods g','g.id=s.goods_id','LEFT')
    ->field('s.*,g.goods_name as goods_name,c.name as card_name')
    ->where('s.appid','eq',USER_APPID)
    ->where('s.openid','eq',$post['openid'])
    ->limit(intval($post['start']), intval($post['length']))
    ->order('time DESC')
    ->select();

tp文档:https://www.kancloud.cn/manual/thinkphp5/118083

没有评论

发表评论