duai4512 2015-01-26 03:39
浏览 66

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图