thinkPHP三表关联查询
三个表,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