以下查询我试图在我的朋友个人资料上显示帖子,但它显示在我的朋友而不是用户表格中的朋友
我的数据库结构是,
Friends_details
Friend_id ---- PROFILE_ID ------ Friend_with
1 ---------------- 1 ---------------- 2
2 ---------------- 2 ---------------- 1
3 ---------------- 1 ---------------- 3
4 ---------------- 3 ---------------- 1
5 ---------------- 4 ---------------- 3
6 ---------------- 3 ---------------- 4post_details
post_id ---------------- profile_id --------------- Frind_id1 ---------------- 1 ---------------- 1,2
2 ---------------- 2 ---------------- 1,2
3 ---------------- 3 ---------------- 3,4,5,6
4 ---------------- 4 ---------------- 5,6Img_post_details
Image_id ---------------- Post_id
1 ---------------- 1
2 ---------------- 2
3 ---------------- 3
4 ---------------- 4
$fid[]=$row_post['frnd_id'];
//echo $fid;
foreach($fid as $frnd)
{
$excludes=explode(',',$frnd);
//print_r(explode(',' ,$frnd));
//\$a=print_r($excludes);
$query_img="SELECT * FROM upload_post.post_details pd
INNER JOIN upload_post.image_post_details ipd
ON pd.post_id = ipd.post_id
INNER JOIN social_panel_db.friends_details fd ON fd.friends_id=pd.frnd_id
WHERE pd.profile_id=".$rows['profile_id']." OR pd.profile_id=".$_SESSION['pro_id']."
AND fd.req_friend_profile_id IN(".$frnd.") OR fd.profile_id IN(".$frnd.") AND fd.frend_request_status=2 AND fd.profile_id=".$_SESSION['pro_id']." OR fd.req_friend_profile_id=".$_SESSION['pro_id']." order by pd.post_id desc";
}
答案 0 :(得分:0)
您需要加入另一个表格才能获取朋友个人资料的ID。当2个人成为朋友时,您应该输入2个值(对于您当前使用的模式)。
示例:
Friends_details
Friends_id Profile_id Friend_with status
1 1 2 conf
2 2 1 conf
这种方式是双向的,id为1的用户是id为2的用户的朋友,反之亦然。
$query_img="SELECT * FROM upload_post.post_details pd
INNER JOIN upload_post.image_post_details ipd
ON pd.post_id = ipd.post_id
INNER JOIN Friends_details fd
ON fd.Friends_id = pd.Frnds_id
WHERE pd.profile_id = " . $_SESSION['pro_id'] . "
AND fd.Friend_with = " . $row_post['frnd_id'] . "";