thinkPHP中使用join进行两个表关联查询
2022-11-24 11:10:29
884
{{single.collect_count}}

在thinkPHP中两个表关联查询是最常用到的,其中有table(),join(),那么下面我就说下join的方法怎么使用吧!

<?phpnamespace Home\Controller;use Think\Controller;class TestController extendsController { protected $check; public function _initialize(){ //初始化一个检查表 $this->check = M('check'); } public function getAllData(){ //使用检查表的uid和userinfo表的id进行关联 $checkList = $this->check->join(array('userinfo on userinfo.id=check.uid'))->field('userinfo.`Name`, userinfo.Number, userinfo.Lost,userinfo.inquiryopen,check.CyTaAuReODDS,check.CyTaAuReODDC')->select(); }}
回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}