title: PHP Query Statement 3 Tables Join
body: <p>I am quite stuck with one query statement.</p>
  
  <p>I have the current query: </p>
  
  <pre><code>$user_id = $_SESSION["user_id"];
  
  $stm = $db-&gt;prepare("SELECT votes.hasVoted
  FROM votes 
  INNER JOIN posts
      ON posts.post_id = votes.post_id 
  INNER JOIN users
      ON users.users_id = votes.user_id 
      WHERE users.user_id = :user_id;");
  $stm-&gt;bindParam(':user_id', $user_id);
  $stm-&gt;execute();
  $votes = $stm-&gt;fetchAll();
  </code></pre>
  
  <p>It is not working.</p>
  
  <p>I have 3 tables. [Votes, Posts, Users].
  I want to retrieve 'hasVoted' value from Votes table according to the session variable of the logged in user.</p>
  
  <p>Votes Table:</p>
  
  <p><a href="https://i.stack.imgur.com/ZsHZc.png" rel="nofollow noreferrer">https://i.stack.imgur.com/ZsHZc.png</a></p>
  
  <p>Posts Table:</p>
  
  <p><a href="https://i.stack.imgur.com/piLPu.png" rel="nofollow noreferrer">https://i.stack.imgur.com/piLPu.png</a></p>
  
  <p>Thanks in advance.</p>
  
  <p>What I need help with:
  In my code I want to check if a logged in user is has voted on a specific post, if yes then the button will turn unclickable.</p>
  
  <p>I have 3 connected Tables.</p>
  
  <pre><code>Votes Table has:
  vote_id [PK]
  user_id [FK]
  post_id [FK]
  
  Posts Table has:
  post_id [PK]
  user_id [FK]
  
  Users Table has:
  user_id [PK]
  </code></pre>
  
  <p>I want to interconnect them with Votes so I can access post_id and user_id from Votes</p>