Rumah > Artikel > pembangunan bahagian belakang > thinkphp+mysql中出现的关联模型问题?
我定义了一张关系表MemberSchool,里面存放的字段有college_id,senior_id,major_id
还有另外三张表college,senior,major表
这是我原先用查询语言的代码
<code>$memberSchool = M('Memberschool'); $where['member_id'] = array('EQ',$this->member_id); $result = $memberSchool->field('college_name,major_name,school_name') ->join('JOIN __COLLEGE__ ON __MEMBERSCHOOL__.college_id = __COLLEGE__.college_id') ->join('JOIN __SENIOR__ ON __MEMBERSCHOOL__.senior_id = __SENIOR__.id') ->join('JOIN __MAJOR__ ON __MEMBERSCHOOL__.major_id = __MAJOR__.major_id') ->where($where) ->find(); return $result;</code>
现在我想利用关联模型的语句把他们的数据查询出来,请问要怎么查询呢?要以哪个表作为参照表呢?
我定义了一张关系表MemberSchool,里面存放的字段有college_id,senior_id,major_id
还有另外三张表college,senior,major表
这是我原先用查询语言的代码
<code>$memberSchool = M('Memberschool'); $where['member_id'] = array('EQ',$this->member_id); $result = $memberSchool->field('college_name,major_name,school_name') ->join('JOIN __COLLEGE__ ON __MEMBERSCHOOL__.college_id = __COLLEGE__.college_id') ->join('JOIN __SENIOR__ ON __MEMBERSCHOOL__.senior_id = __SENIOR__.id') ->join('JOIN __MAJOR__ ON __MEMBERSCHOOL__.major_id = __MAJOR__.major_id') ->where($where) ->find(); return $result;</code>
现在我想利用关联模型的语句把他们的数据查询出来,请问要怎么查询呢?要以哪个表作为参照表呢?