Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在不同的页面/配置文件上显示不同的结果_Mysql_Sql_Pdo - Fatal编程技术网

Mysql 在不同的页面/配置文件上显示不同的结果

Mysql 在不同的页面/配置文件上显示不同的结果,mysql,sql,pdo,Mysql,Sql,Pdo,我不知道我是否在大脑中丢失了这些信息,或者我从未拥有过这些信息,但我已经创建了一条推特,这样一个用户就可以跟踪其他用户 现在的问题是每个用户都显示相同的信息。 我试图将WHERE$\u SESSION['uid']添加到我的查询中,但这无助于实现这一目的 仍然显示相同的信息。 有什么建议吗 <?php foreach(fetch_follotweets() as $tweet){ echo $tweet['firstname']; echo $

我不知道我是否在大脑中丢失了这些信息,或者我从未拥有过这些信息,但我已经创建了一条推特,这样一个用户就可以跟踪其他用户

现在的问题是每个用户都显示相同的信息。 我试图将WHERE
$\u SESSION['uid']
添加到我的查询中,但这无助于实现这一目的

仍然显示相同的信息。 有什么建议吗

<?php 
    foreach(fetch_follotweets() as $tweet){ 
        echo $tweet['firstname']; 
        echo $tweet['lastname'];
        echo $tweet['username'];
        echo $tweet['date'];
        echo $tweet['profile_img'];
        $tweet['message'];
    }

    function fetch_follotweets(){
        global $db;
        $query = $db->query("   SELECT
                                  user.email,
                                  user.username,
                                  tweets.message,
                                  tweets.date,
                                  userdetails.profile_img,
                                  userdetails.firstname,
                                  userdetails.lastname,
                                  following.id,
                                  following.user_id,
                                  following.follow_id
                                FROM user
                                  JOIN userdetails
                                    ON user.id = userdetails.user_id
                                  JOIN tweets
                                    ON userdetails.user_id = tweets.user_id
                                  JOIN following
                                    ON following.follow_id
                                WHERE following.follow_id = tweets.user_id AND
                                user.id='{$_SESSION['uid']}
                                ORDER BY tweets.date DESC");
            $tweet = array();
        while(($row = $query->fetch(PDO::FETCH_ASSOC)) !==FALSE) { 
            $tweet[] = $row;
        }
        return $tweet;
    }
    ?>

如果没有
WHERE
子句,
SQL
将获得所有用户的详细信息

此外,我认为
tweets
&
上的
加入
应该是
左加入
(以获取
记录
,即使它们都不存在)


你想干什么。你需要所有的记录吗?或者,当用户登录时,您是否在显示信息,而用户只能看到他的信息?@raheelshan这是一个个人资料网站,显示您正在关注的推文。就像推特一样。我可以输入不同的个人资料。但每个个人资料都应该只显示你关注的推文。现在每个配置文件都显示相同的tweet。我看到您没有分配id来限制与tweet相关的结果user@raheelshan这就是问题所在,当我添加user.id='{$\u SESSION['uid']}时,它只返回空值results@Dymond我已经更新了答案,您的加入似乎也有问题,请检查我觉得查询很好,除非你的记录有其他问题!!(对于特定的用户,请尝试直接在
SQL
控制台上启动它。另外,请确保使用
session\u start()
在您使用的页面中,查询很好。这没有问题。我希望每个配置文件都显示自己的查询。就像这样。用户1-关注用户2。在用户1的配置文件上,您只看到用户2的推文。现在每个配置文件都显示用户关注的所有内容。我认为m不清楚您的要求e、 是不是在user1的主页上,您希望显示user1和user2的推文列表(如果是user1同事的user2)?
SELECT
  user.email,
  user.username,
  tweets.message,
  tweets.date,
  userdetails.profile_img,
  userdetails.firstname,
  userdetails.lastname,
  t.ids_of_users_followed
FROM 
  user
  JOIN userdetails
    ON user.id = userdetails.user_id
  LEFT JOIN (
      SELECT
        GROUP_CONCAT( following.follow_id ) AS ids_of_users_followed
        following.user_id
      FROM
        following
      GROUP BY
        following.user_id
    ) as t ON ( t.user_id = user.id )
  JOIN tweets
    ON ( userdetails.user_id = tweets.user_id OR FIND_IN_SET( tweets.user_id, t.ids_of_users_followed ) )
WHERE 
  user.id = :?    => Make sure to add the logged in user_id here
ORDER BY 
  tweets.date DESC