预期结果是 12(price) 和 pic.png(profilepic)。这是否可以根据匹配的 job_id(工作+优惠)加入工作和个人资料,这些工作和个人资料在个人资料和优惠之间具有匹配的用户 ID,所有这些都基于 $_SESSION[user_id]? Jobs Offers Profileuser_id | job_id | price | | user_id | job_id | |user_id | profilepic | 1 | 1 | 12 | | 4 | 1 | | 4 | pic.png |-------------------------- -------------------- -----------------------$sql="SELECT j.price, p.profilepic FROM Jobs j INNER JOIN Offers o ON o.job_id = j.job_id INNER JOIN Profile p ON o.user_id = p.user_id WHERE user_id=?";$stmt = $conn->prepare($sql);$stmt->bind_param("i",$_SESSION['user_id']);$stmt->execute();$stmt->bind_result($price,$profilepic);$stmt->fetch();它不起作用,这可能吗?
2 回答
人到中年有点甜
TA贡献1895条经验 获得超7个赞
您的查询看起来很好。您只需要用它所属的表来限定子句user_id中的列:from
SELECT j.price, p.profilepic
FROM Jobs j
INNER JOIN Offers o ON o.job_id = j.job_id
INNER JOIN Profile p ON o.user_id = p.user_id
WHERE p.user_id = ? -- or j.user_id = ?
梵蒂冈之花
TA贡献1900条经验 获得超5个赞
MySQL 不喜欢你有两个相同的列名为userid. 所以只需为 where 子句选择一个
$sql="SELECT
j.price,
p.profilepic
FROM Jobs j
INNER JOIN Offers o ON o.job_id = j.job_id
INNER JOIN Profile p ON o.user_id = p.user_id
WHERE j.user_id=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i",$_SESSION['user_id']);
$stmt->execute();
$stmt->bind_result($price,$profilepic);
$stmt->fetch();
- 2 回答
- 0 关注
- 101 浏览
添加回答
举报
0/150
提交
取消