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

This 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

is supposed to select posts, user data, and verify that the user is friends with the other user. The user viewing this is defined by $UID, fUID is the friends UID and friend is the second friends UID.

The problem is that when this is displayed to the user, all of the users posts are showed twice, but other ones from other users are only displayed once.

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>';
            }
}

EDIT: I've put actual values into the sql instead of using variables, but that doesn't seem to help.