Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL query for multiple users and multiple tables with PHP
    primarykey
    data
    text
    <p>I'm having a bit of trouble figuring out how to make a query to achieve the following situation. I want a user to be able to view their events and activities (two different tables), along with any events/activities of organizations they belong to sorted by date</p> <p>Events Table</p> <pre><code>eventID | eventTitle | eventBy | eventDate 1 Event 1 1 2012/10/11 2 Event 2 2 2012/10/08 3 Event 3 3 2012/10/05 </code></pre> <p>Activities table</p> <pre><code>postID | postTitle | postBy | postDate 1 activity 1 1 2012/10/07 2 activity 2 2 2012/10/09 </code></pre> <p>orgMembers table </p> <pre><code>orgID | userID 2 1 //userID 1 is a member of groupID 2 </code></pre> <p>Anyway, I'm trying to get the results to look be the following if userid 1 is viewing the page</p> <pre><code> Title By Date Activity 1 1 2012/10/07 Event 2 2 2012/10/08 Activity 2 2 2012/10/09 Event 1 1 2012/10/11 </code></pre> <p>This query results in ONLY my posts only showing, not the organization that I'm a member of too.</p> <pre><code>select eventTitle as title, eventID as ids, eventBy as byUser, users.username, eventDate as date from events inner join users on users.userid = events.eventBy where eventBy in (select distinct g1.userID from orgMembers g1 inner join orgMembers g2 on g1.orgID = g2.orgID where g2.userID = '$id') or eventBy = '$id' UNION select postTitle as description, postID as ids, postBy as byUser, users.username, postDate as date from posts inner join users on users.userid = posts.postBy where postBy in (SELECT distinct g1.userID FROM orgMembers g1 inner join orgMembers g2 on g1.orgID = g2.orgID where g2.userID = '$id') or postBy = '$id' Order BY date" </code></pre>
    singulars
    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.
    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