Home > Backend Development > PHP Tutorial > thinkphp关联查询问题,join

thinkphp关联查询问题,join

WBOY
Release: 2016-06-23 14:24:13
Original
831 people have browsed it

thinkphp 关联查询

$result = $room->join('r_hospital on r_department.hospital_id=r_hospital.id')->where(array('hospital_id'=>array('exp','is not null')))->select();
大神们看看,where(array('hospital_id'=>array('exp','is not null')))这句话是什么意思?结果显示出来所有的医院,但我只想查某一个,把医院id等于$data,怎么做

回复讨论(解决方案)

没人会吗?难到就那么难吗

从字面理解是hostpital_id中非NULL空的都选择

$condition['hospital_id'] = $data;
// 把查询条件传入查询方法
$result = $room->join('r_hospital on r_department.hospital_id=r_hospital.id')->where($condition)->select(); 

$condition['hospital_id'] = $data;
// 把查询条件传入查询方法
$result = $room->join('r_hospital on r_department.hospital_id=r_hospital.id')->where($condition)->select(); 
恩,确实是这种方法。三级关联的怎么写,再添加一个医生doctor的id

$condition['hospital_id'] = $data;
// 把查询条件传入查询方法
$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(); 

$condition['hospital_id'] = $data;
// 把查询条件传入查询方法
$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(); 
谢了

$condition['hospital_id'] = $data;
// 把查询条件传入查询方法
$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(); 
这个是三级关联的吗?貌似不行呀。帮我写个三级关联的吧,医生属于科室,科室属于医院这种关系。我弄了很久了,就是不会

请帖出3张表结构

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template