php - Getting posts from your friends -
what trying accomplish fill news feed full of posts friends of $username session username.
the problem have if user not following or not being followed (is not in follow table) not see own posts in news feed.
everything else seems work fine.
user can see post , people follows post. user can see posts if following or being followed. user cannot see own post if not following nor being followed.
select p.* posts p join follow f on p.by in (f.person_being_followed, '$username') '{$username}' in (f.person_following, p.by) order p.id desc
this code page echo information
<? $get_posts = mysql_query("select p.* posts p join follow f on p.by in (f.person_being_followed, '$username') ### ,$username' shows logged users posts, if in follow table ### '{$username}' in (f.person_following, p.by) ## p.by shows person posted logged in, if in follow table ## order 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 follow
mysql table posts
replace
$get_posts = mysql_query("select posts.* posts inner join follow on posts.by=follow.person_being_followed follow.person_following = $username order posts.id desc");
with
$get_posts = mysql_query("select posts.* posts inner join follow on posts.by=follow.person_being_followed follow.person_following = '$username' order posts.id desc") or die(mysql_error());
use mysql_error()
debugging purpose see if error message printed out
Comments
Post a Comment