title: if else statement connect to DB unique for logged in user
body: <p>I creating a twitter look a like platform for studying purpose, I have reach to the follow and unfollow part.</p>
  
  <p>I have two buttons, the follow and unfollow button, they both works fine If i press follow it insert session ID and the id of the user i want to follow. If i press unfollow it removes that row.
  all good.</p>
  
  <p>I have now added ad if else statement to the buttons so if you press the follow button it changes to unfollow and by pressing the unfollow it changes back to follow.</p>
  
  <p>The problem is that since the if else works depending if the row is empty or not, it gives me back the same results for every logged in user.
  Maybe there is a better way to show the buttons ?</p>
  
  <p>This is what I have for now.</p>
  
  <pre><code>    &lt;?php foreach(fetch_users($_GET['uid'])as $user){   
  
  
      if(empty($user['follow_id'])){ ?&gt; &lt;form action="" method='POST'&gt;
      &lt;button type="submit" class="follow" name="submit" value="&lt;?php echo $user['id'] ?&gt;"/&gt;FOLLOW&lt;/button&gt; 
      &lt;/form&gt;
  
  &lt;?php }    else{     ?&gt;
      &lt;form action="" method='POST'&gt;
      &lt;button type="submit" class="follow" name="delete" value="&lt;?php echo $user['id'] ?&gt;"/&gt;UNFOLLOW &lt;/button&gt; 
      &lt;/form&gt;
      &lt;?php 
      }
      ?&gt;
      &lt;/form&gt;
  
  
      &lt;/div&gt;
      &lt;?php } ?&gt;
  
  
  function fetch_users($uid){
  global $db;
  $query = $db-&gt;query("SELECT user.id, user.username, user.email, userdetails.profile_img, following.follow_id
  FROM user
  JOIN userdetails ON user.id = userdetails.user_id
  LEFT JOIN following ON user.id = following.follow_id
  WHERE user.id != '{$uid}' ");
  $user = array();
  while(($row = $query-&gt;fetch(PDO::FETCH_ASSOC)) !==FALSE) { 
  $user[] = $row;
  
  }
  return $user;
  }
  </code></pre>