我的墙脚本有问题,一个帖子在用户自己的墙上多次显示,一次在他的朋友墙上显示。例如,如果我有 5 个朋友,脚本将显示单个帖子 5 次。
由于它在朋友墙上显示过一次,这部分工作良好,但问题出在用户自己的墙上。
PHP代码:
$qfu = "SELECT * FROM my_friends WHERE (user_id = '$user_id' OR friend_id = '$user_id') AND status = '1'";
$fu = mysql_query($qfu) or die(mysql_error());
$rowfu = mysql_num_rows($fu);
while ($rowf = mysql_fetch_array($fu)) {
$user_id = $rowf['user_id'];
$friend_id = $rowf['friend_id'];
$querymsgs = "SELECT * FROM messages where uid_fk = '$friend_id' OR uid_fk = '$user_id' order by msg_id DESC Limit 1";
$qmsgs = mysql_query($querymsgs) or die(mysql_error());
$row_msgs = mysql_num_rows($qmsgs);
while ($msgs = mysql_fetch_array($qmsgs)) {
$msg_id = $msgs['msg_id'];
$orimessage = $msgs['message'];
$message = tolink(htmlentities($msgs['message']));
$time = $msgs['created'];
$privacy = $msgs['privacy'];
if ($privacy == '0') {
$privacy = 'Only Me';
} elseif ($privacy == '2') {
$privacy = 'Public';
} else {
$privacy = 'Friends';
}
$uid = $msgs['uid_fk'];
$fullname = $msgs['fname'] . " " . $msgs['lname'];
$face = $Wall->Avatar($uid);
$commentsarray = $Wall->Comments($msg_id);
?>
我也尝试过下面的代码,但它也多次显示相同的帖子:
$qfu = "SELECT * FROM my_friends WHERE (user_id = '$user_id' OR friend_id = '$user_id') AND status = '1'";
$fu = mysql_query($qfu) or die(mysql_error());
$rowfu = mysql_num_rows($fu);
while ($rowf = mysql_fetch_array($fu)) {
if ($user_id == $rowf['user_id']) {
$fid = $rowf['friend_id'];
} else {
$fid = $rowf['user_id'];
}
$querymsgs = "SELECT * FROM messages M, tbluser U WHERE U.id='$user_id' and M.uid_fk=U.id and (M.privacy='1' or M.privacy='2') order by M.msg_id desc ";
$qmsgs = mysql_query($querymsgs) or die(mysql_error());
$row_msgs = mysql_num_rows($qmsgs);
$msgs = mysql_fetch_array($qmsgs);
$msg_id = $msgs['msg_id'];
$orimessage = $msgs['message'];
$message = tolink(htmlentities($msgs['message']));
$time = $msgs['created'];
$privacy = $msgs['privacy'];
if ($privacy == '0') {
$privacy = 'Only Me';
} elseif ($privacy == '2') {
$privacy = 'Public';
} else {
$privacy = 'Friends';
}
$uid = $msgs['uid_fk'];
$fullname = $msgs['fname'] . " " . $msgs['lname'];
$face = $Wall->Avatar($uid);
$commentsarray = $Wall->Comments($msg_id);
?>
请帮助我摆脱这个问题。