gpt4 book ai didi

php - 带有 JOIN 的 MySQL 查询未正确执行

转载 作者:行者123 更新时间:2023-11-29 00:35:16 25 4
gpt4 key购买 nike

我没有得到任何数据,我已经检查了我父亲应该匹配的数据

我有两个表,likesuser_follow我正在尝试通过一个 ID 将两个表关联起来。

表 - 列

likes - idlikes、iduser、信息user_follow - iduser_follow、iduser_follower、iduser_following

$following = $dbh -> prepare("SELECT L.* FROM likes L JOIN user_follow F ON F.iduser_following = L.iduser WHERE F.iduser_follower = ?");
$following->execute(array($_SESSION['user_auth']));
while($row_following = $following->fetch(PDO::FETCH_ASSOC)){
$id_1 = $row_following['L.information']; // get id of user that i'm following
echo $id_1;
}

因此,如果我关注某人,我应该能够显示与我关注的任何人相关的信息。

我没有收到任何错误,只是没有回显任何内容?


示例数据

用户关注

iduser_follow           iduser_follower            iduser_following
1 2 3
2 2 4

喜欢

  idlikes                   iduser                  information
1 3 info1
2 3 info2

所以,假设 $_SESSION['user_auth'] = 2,我应该输出 info1 和 info2,对吗?

最佳答案

SELECT  b.*
FROM user_follow a
INNER JOIN likes b
ON a.iduser_following = b.iduser
WHERE a.iduser_follow = 'myuserID' AND
iduser_following = 'followingID'

获取值

$id_1 = $row_following['information'];

关于php - 带有 JOIN 的 MySQL 查询未正确执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14658010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com