此查询:
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而不是使用变量,但这似乎没有帮助。