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

时间:2021-06-08 01:07:46

I'm not getting any data, and I've checked my dad which should match up

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

I have two tables, likes and user_follow I'm trying to tie the two tables by an id.

我有两个表,喜欢和user_follow我试图用id绑定两个表。

Table - Column

表 - 列

likes - idlikes, iduser, information user_follow - iduser_follow, iduser_follower, iduser_following

喜欢 - 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;
}

So if i'm following someone, i should be able to display information associated with whomever I'm following.

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

I don't get any errors, it just doesn't echo out anything?

我没有得到任何错误,它只是没有回应任何东西?


Sample Data

user_follow

iduser_follow           iduser_follower            iduser_following
     1                         2                        3
     2                         2                        4

likles

  idlikes                   iduser                  information
     1                         3                        info1
     2                         3                        info2

So, I should output info1 and info2, assuming that $_SESSION['user_auth'] = 2, correct?

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

1 个解决方案

#1


1  

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'

and fetch value

并获取值

$id_1 = $row_following['information'];

#1


1  

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'

and fetch value

并获取值

$id_1 = $row_following['information'];