thinkphp 表关联,大神请教一下

thinkphp3.2.3
有两张表,
shop表中有 id,name字段
shop_period表中有 sid字段
shop的id 就是 shop_period的sid

想要统计shop_period 里sid出现的次数,然后关联shop表

大神,这样要怎么操作,是用join还是用table,怎么用,谢谢

阅读 2k
1 个回答
M('shop')->join('a left join __SHOP_PERIOD__ b on a.id = b.sid')->field('a.*,count(b.sid)')->select();

打印的数据应该是这样的
Array ( [0] => Array ( [id] => 1 [count(b.item_id)] => 25 ) )

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进