这是我的sql查询:
function show($conn){
$ask=" SELECT people.per_id, people.per_name , people.hos_id,
people.car_id, people.us_id FROM people
inner join house on house.hos_id = house.hos_id
inner join car on people.car_id = car.car_id
inner join user on people.us_id = user.us_id ";
$query = $conn->prepare($ask);
$query->execute();
return $query;
}
查询显示示例
people.per_id = 1
people.per_name = mark
people.hos_id = 3
people.car_id = 5
people.us_id = 7
我想看的
people.per_id = 1
people.per_name = mark
people.hos_id = green house
people.car_id = suv
people.us_id = faster
如何通过ID来访问桌房,汽车和用户中的其他数据?
答案 0 :(得分:1)
尝试
使用house.house_name
代替people.hos_id
,car.car_name, user.user_name
并写people.hos_id = house.hos_id
代替house.hos_id = house.hos_id
function show($conn){
$ask=" SELECT people.per_id, people.per_name , house.house_name,
car.car_name, user.user_name FROM people
inner join house on people.hos_id = house.hos_id
inner join car on people.car_id = car.car_id
inner join user on people.us_id = user.us_id ";
$query = $conn->prepare($ask);
$query->execute();
return $query;
}
答案 1 :(得分:0)
您可以在下面尝试-
您需要从其他表中选择名称,例如house.name,car.name, user.name
而不是ids
列
SELECT people.per_id, people.per_name , house.name,car.name, user.name FROM people
inner join house on people.hos_id = house.hos_id
inner join car on people.car_id = car.car_id
inner join user on people.us_id = user.us_id