SQL在页面上显示重复结果以供查看用户

时间:2015-01-26 03:39:27

标签: php mysql

此查询:

SELECT DISTINCT `social_posts` . * , `social_friends` . * , `users` . *
FROM `social_posts`
JOIN `social_friends` ON `friend` = `pUID`
JOIN `users` ON `friend` = `uid`
WHERE `fUID` = '$UID' OR `friend` = '$UID'
ORDER BY `date` DESC
LIMIT 0 , 30

应该选择帖子,用户数据,并验证用户是否与其他用户成为朋友。查看此内容的用户由$UID定义,fUID是朋友UID,friend是第二个朋友UID。

问题在于,当向用户显示此消息时,所有用户帖子都会显示两次,但其他用户的其他帖子只显示一次。

PHP:

$query = "SELECT DISTINCT `social_posts` . * , `social_friends` . * , `users` . *
    FROM `social_posts`
    JOIN `social_friends` ON `friend` = `pUID`
    JOIN `users` ON `friend` = `uid`
    WHERE `fUID` = '$UID' OR `friend` = '$UID'
    ORDER BY `date` DESC
    LIMIT 0 , 30";
        $data = mysqli_query($dbc, $query);
        while ($row = mysqli_fetch_array($data)){
            $ID = $row['pid'];
            $parsed = $parser->parse($row['body']);
            echo '<div class="shadowbar">';
            echo sprintf($layout['socialViewFormat'], $row['picture'], $row['uid'], $row['username'], date('M j Y g:i A', strtotime($row['date'])), $parsed);
            $cQ = "SELECT users.*, comments.* FROM `comments` JOIN `users` ON `user` = `uid` AND `module` = 'social' AND `id` = '$ID'";
            $cD = mysqli_query($dbc, $cQ);
            while($cR = mysqli_fetch_array($cD)){
                $body = htmlentities($cR['cBody']);
                echo '<pre><a href="/ucp/uid/'.$cR['uid'].'">' . $cR['username'] . '</a><hr style="padding:0; margin:0;" />';
                echo ''.$body.'</pre>';
            }
}

编辑:我已将实际值放入sql而不是使用变量,但这似乎没有帮助。

0 个答案:

没有答案