gpt4 book ai didi

php - Wall 脚本的问题

转载 作者:行者123 更新时间:2023-11-30 01:26:14 25 4
gpt4 key购买 nike

我的墙脚本存在问题,单个帖子在用户自己的墙上显示多次,在他的 friend 墙上显示一次。例如,如果我有 5 个 friend ,脚本将显示单个帖子 5 次。

由于它在 friend 墙上显示过一次,这部分工作正常,但问题出在用户自己的墙上。

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);
?>

请帮我解决这个问题。

最佳答案

我认为问题出在这个语句中:$qfu = "SELECT * FROM my_friends WHERE (user_id = '$user_id' ORfriend_id = '$user_id') AND status = '1'"; - 如果您有 5 个 friend ,您的 id 将在结果中出现 5 次,因此您的帖子将出现 5 次。

您应该删除查询的 user_id = '$user_id' 部分:
$qfu = "SELECT * FROM my_friends WHEREfriend_id = '$user_id' AND status = '1'"; - 这样您只能获取您的好友。您已经有自己的 id,因此无需查询。

现在您需要将获取消息的代码放入单独的函数中,您就准备好了:

function getMessagesById($authorId) {
$querymsgs = "SELECT * FROM messages where uid_fk = '$authorId' order by msg_id DESC";
$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);
}

//get all own messages
getMessagesById($userId);

//get all friends' messages
$qfu = "SELECT * FROM my_friends WHERE 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)) {
$friend_id = $rowf['friend_id'];
getMessagesById($friend_id);
}

关于php - Wall 脚本的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17957669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com