gpt4 book ai didi

php - 从你的 friend 那里获取帖子

转载 作者:行者123 更新时间:2023-11-29 00:31:16 25 4
gpt4 key购买 nike

我想要完成的是用 $username 的 friend 的帖子填充新闻提要,$username 是 session 用户名。

我现在遇到的问题是,如果用户没有关注任何人或没有被任何人关注(不在关注表中),那么他们将不会在新闻提要中看到自己的帖子。

其他一切似乎都正常。

用户可以看到他们的帖子和他们关注的人。如果用户正在关注或被关注,他们可以看到他们的帖子。如果用户未关注或未被关注,则他们看不到自己的帖子。

SELECT  p.*
FROM posts p
JOIN follow f
ON p.by IN (f.person_being_followed, '$username')
WHERE '{$username}' IN (f.person_following, p.by)
ORDER BY p.id DESC

这也是页面回显此信息的代码

        <?

$get_posts = mysql_query("SELECT p.*
FROM posts p
JOIN follow f
ON p.by IN (f.person_being_followed, '$username') ### the ,$username' shows the logged users posts, but only if they are in the follow table ###
WHERE '{$username}' IN (f.person_following, p.by) ## the p.by shows the person who posted who logged in, but only if they are in the follow table ##
ORDER BY p.id DESC") or die(mysql_error());

while ($post_row = mysql_fetch_assoc($get_posts)) {

include './includes/newsfeed/postdetails.tpl';
include './includes/newsfeed/likeinfo.tpl';
include './includes/newsfeed/fandlname.tpl';
include './includes/newsfeed/deletepostbutton.tpl';

?>


<div style='display: inline-block;width: 560px;padding-top: 10px;padding-bottom: 10px; border-bottom: 1px solid rgba(0,0,0,0.1);'>
<a style='float: left;' href='./profile.php?u=<?
echo $post_by;
?>'><img src='' height='50px' width='50px'/></a>
<div style='float: right; width: 500px;'>
<p style='color: rgb(59, 152, 96);font-weight: bold; font-size: 13px;
line-height: 1.38;font-family: 'lucida grande',tahoma,verdana,arial,sans-serif;'><a style='color: rgb(59, 152, 96);
font-weight: bold;
font-size: 12px;
line-height: 1.38;text-decoration: none;' href='./profile.php?u=<?
echo $post_by;
?>'><?
echo "$fnamepost $lnamepost";
?></a></p>
<p style='color: rgb(51, 51, 51);
font-size: 13px;
line-height: 1.38;
font-family: 'lucida grande',tahoma,verdana,arial,sans-serif;'><?
echo $post_content;
?></p>

<div style='margin-top: 5px;'><a href='./scripts/like.php?pid=<?
echo $post_id;
?>' style='color:rgb(109, 180, 137);
font-size: 11px;line-height: 1.28;'><?
echo "$likedornot ($countlikes)";
?></a><a href='#' class='comment_button' style='margin-left: 10px;color:rgb(109, 180, 137);
font-size: 11px;line-height: 1.28;'><?
echo "Comment";
?></a><?
echo $deletecodevariable;
?></div>

<?
include './includes/newsfeed/comments.tpl';
?>
</div></div>
<?
}
?>

关注的mysql表

also this is my table for follow

用于帖子的 mysql 表

and this is my table for posts

最佳答案

替换

$get_posts = mysql_query("SELECT posts.*            
FROM posts
INNER JOIN follow
ON posts.by=follow.person_being_followed
WHERE follow.person_following = $username
ORDER BY posts.id DESC");

$get_posts = mysql_query("SELECT posts.*            
FROM posts
INNER JOIN follow
ON posts.by=follow.person_being_followed
WHERE follow.person_following = '$username'
ORDER BY posts.id DESC") or die(mysql_error());

使用 mysql_error() 进行调试以查看是否打印出任何错误消息

关于php - 从你的 friend 那里获取帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16373896/

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