Home >Backend Development >PHP Tutorial >thinkPHP三表关联查询

thinkPHP三表关联查询

WBOY
WBOYOriginal
2016-06-23 14:24:141290browse

thinkphp join 三表关联

三个表,r_hospital表    r_department表        r_doctor表
       id              id hospital_id        id depart_id  hospital_id
三个表所属关系如上,
两个表关联:我会了,
$condition['hospital_id'] = $data;
// 把查询条件传入查询方法
$result = $room->join('r_hospital on r_department.hospital_id=r_hospital.id')->where($condition)->select();  
求三个表关联语句?

$result = $room->join('left join r_hospital on r_department.hospital_id=r_hospital.id  left join doctor on doctor.id = xx.id')->where($condition)->select(); 这语句不对,不知道哪有问题

回复讨论(解决方案)

可以一直jion下去

你先把表的主外键关系理清楚,再写sql

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn