dongyi1441 2012-02-25 17:18 采纳率: 100%
浏览 19
已采纳

棘手的社交网络墙码逻辑

The goal:

pull from members walls - if two friends share the same churchMember relationship, show streams

pull following tables:

  • friends
  • wallPosts
  • users
  • churchMembers

table structures:

friends table:

- id, node1id, node2id

wallPosts:

- entryData
- postingUserId

users:

- userpid
- username
- firstname
- lastname

church members:

- churchid
- userid

How would I put the above requirements into code?

Update:

select all rows that have the same churchId as the one that the user logged in is connected with $churchId = '1';

SELECT * FROM churchMembers WHERE  cMchurchId = $churchId
if $row-cMchurchId == $churchId
    SELECT * FROM churchMembers, users WHERE churchMembers.cMuserId = users.userid
  • 写回答

1条回答 默认 最新

  • doucaigai7176 2012-02-25 17:46
    关注

    this should get you started:

    $friendId = 5;
    
    $sql = "select w.entryData from wallposts w
            inner join church_members cm 
              on cm.userid = w.postingUserId
            where cm.churchid = 
              (SELECT churchid from church_members where userId='" + $friendId + "'");
    

    ok, if those are userid's in the friends table, you can go like this:

    select w.entryData from friends f
    inner join church_members cm on f.node2id = cm.userid  //<--friends church
    inner join church_members cm2 on f.node1id = cm2.userid //<-- my church
    inner join wallposts w on w.postingUserId = f.node2Id //<-- grab the friends wallposts
    inner join users u on f.node2id = u.userpid //<-- grab the user data
    where cm2.church_id = cm.church_id //<-- they got's to be the same :)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改