目标:
从会员墙上拉 - 如果两个朋友共享同一个churchMember关系,则显示流
拉下表:
表格结构:
朋友表:
- id, node1id, node2id
wallPosts:
- entryData
- postingUserId
用户:
- userpid
- username
- firstname
- lastname
教会成员:
- churchid
- userid
我如何将上述要求纳入代码?
更新
选择与用户登录时具有相同churchId的所有行与$churchId = '1';
SELECT * FROM churchMembers WHERE cMchurchId = $churchId
if $row-cMchurchId == $churchId
SELECT * FROM churchMembers, users WHERE churchMembers.cMuserId = users.userid
答案 0 :(得分:1)
这应该让你开始:
$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 + "'");
好吧,如果那些是朋友表中的用户ID,你可以这样:
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 :)