Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Inner Join for News Feed
    primarykey
    data
    text
    <p>I am having some trouble with the Inner Join aspect of a statement. I am trying to get all the "posts" from a users friends list on their news feed. I'm trying to do so by getting all those posts where the user is the initiator_user_id and get all the posts from the friend_user_id then I want to get all the posts from initiator_user_id where the user's id is the friend_user_id.</p> <p>Previously this works but it only gets the posts where the user is the initiator_user_id:</p> <pre><code>$wallsql= $conn-&gt;prepare('SELECT * FROM activity f INNER JOIN wp_bp_friends n2 ON n2.friend_user_id=f.user_id WHERE n2.initiator_user_id=:userid ORDER BY datetime DESC LIMIT 8'); </code></pre> <p>Userid 24 can see userid 22's "posts" such as when 22's account was created and his status update. What it NEEDS to do is let userid 22 see userid 24's updates as well. Right now it's one sided. I thought that the following would accomplish getting it to go both ways:</p> <pre><code>$wallsql= $conn-&gt;prepare('SELECT * FROM activity f INNER JOIN wp_bp_friends n1 ON (n1.initiator_user_id=f.user_id) INNER JOIN wp_bp_friends n2 ON (n2.friend_user_id=f.user_id) WHERE (n1.friend_user_id=:userid) OR (n2.initiator_user_id=:userid) ORDER BY datetime DESC LIMIT 8'); $wallsql-&gt;bindParam(':userid', $_SESSION['uid']); $wallsql-&gt;execute(); </code></pre> <p>Here is the tables and how they are set up.</p> <pre><code>wp_bp_friends table: id initiator_user_id friend_user_id is_confirmed is_limited date_created 11 24 22 1 0 2013-12-11 11:17:26 Activity table: ID user_id type component filetype group_id content datetime 15 22 accountcreated NULL NULL 0 NULL 2013-12-11 11:17:26 15 22 status NULL NULL 0 Hello World! 2013-12-11 11:17:26 15 24 accountcreated NULL NULL 0 NULL 2013-12-11 11:17:26 15 24 status NULL NULL 0 Whats up 2013-12-11 11:17:26 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload