Reputation: 43
What I am trying to accomplish is to fill a news feed full of posts from friends of $username which is the session username.
The problem I have now is if the user is not following anyone or is not being followed by anyone (is not in the follow table) then they will not see their own posts in their news feed.
Everything else seems to work fine.
User can see their post and people they follows post. User can see their posts if they are following or being followed. User cannot see their own post if they are not following nor being followed.
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
this is also the code for the page to echo this information
<?
$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 table for follow
mysql table for posts
Upvotes: 1
Views: 167
Reputation: 9823
Replace
$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");
with
$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());
Use mysql_error()
for debugging purpose to see if you get any error message printed out
Upvotes: 1