drfu29983 2015-08-08 10:41
浏览 18

数据库提取中的查询

Following query where I am trying to display post on my friends profile but it display on both of my friends and not friend from user table

my database structure is,

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 ---------------- 4

post_details
post_id---------------- profile_id--------------- Frind_id

1---------------- 1---------------- 1,2
2---------------- 2---------------- 1,2
3---------------- 3---------------- 3,4,5,6
4---------------- 4---------------- 5,6

Img_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";

}

  • 写回答

1条回答 默认 最新

  • dongyao2129 2015-08-08 12:00
    关注

    You need to join another table to get the id of your friends profile. And when 2 people become friends, you should enter 2 values (for the schema you are currently using).

    Example:

    Friends_details
    Friends_id  Profile_id  Friend_with status
    1   1   2   conf
    2   2   1   conf
    

    This way it goes both ways, user with id 1 is friends with user with id 2 and vice versa.

    $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'] . "";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计