title: How do I Inner Join users table with followed users posts?
body: <p>I am trying to retrieve the posts from the people the current user is following along with their details. I've been researching at it seems a join is the right way to do it but I am not sure what is wrong with it.</p>
  
  <p>Here is my code</p>
  
  <pre><code>$queryfeed = "SELECT posts.user_id, posts.body, posts.image, posts.has_image 
  FROM posts, follows WHERE posts.user_id =  follows.leader_id 
  AND follows.follower_id =$user_id INNER JOIN users ON users.user_id 
  = follows.leader_id";
  
  $resultfeed = $db-&gt;query($queryfeed);
  if($resultfeed-&gt;num_rows &gt; 0) {
      while( $rowfeed = $resultfeed-&gt;fetch_assoc() ) {       
          if($rowfeed['posts.has_image'] == 1) {
      ?&gt;
              &lt;article class="post"&gt;
                  &lt;div class="post-head cf"&gt;
                      &lt;a class="userpic" href=""&gt;&lt;img src="&lt;?php echo $userpic ?&gt;" alt="&lt;?php echo $rowfeed['users.username'] ?&gt;"&gt;&lt;/a&gt;
                      &lt;a href="" class="username"&gt;
                          &lt;?php echo $rowfeed[users.'username']; ?&gt;
                      &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;img src="users/user_&lt;?php echo $rowfeed['posts.user_id'] ?&gt;/posts/&lt;?php echo $rowfeed['posts.image']; ?&gt;" alt=""&gt;
                  &lt;div class="post-body"&gt;
                      &lt;div class="post-options"&gt;
                          &lt;a class="likes" href=""&gt;2 likes&lt;/a&gt;
                      &lt;/div&gt;
                      &lt;p&gt;
                          &lt;a class="username" href=""&gt;
                                  &lt;?php echo $rowfeed['users.username'] ?&gt;
                          &lt;/a&gt;
                          &lt;?php echo $rowfeed['posts.body'] ?&gt;
                      &lt;/p&gt;
                      &lt;hr /&gt;
                      &lt;div class="cf"&gt;
                          &lt;a class="like hide-text" href="javascript:;"&gt;Like This Post&lt;/a&gt;
                          &lt;form action="" class="comment"&gt;
                              &lt;input type="text" placeholder="Add a comment"&gt;
                          &lt;/form&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/article&gt;
  
     &lt;?php } else { ?&gt;
  </code></pre>
  
  <p>My tables look like this</p>
  
  <pre><code>users
  user_id | username | avatar
  
  posts
  post_id | user_id | body | image | has_image
  
  follows
  leader_id | follower_id
  </code></pre>