Q:

Screwy social network wall code logic

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

A:

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 :)

