adding friends in a while loop
<p>My problem started on the members page of my website where i used a <code>while</code> loop do display all members.</p>

<pre><code>$X_query = mysql_query("SELECT * FROM users");
while($row = mysql_fetch_array($X_query)) {
  $X_id = $row['X'];
  $X_firstname = $row['X'];
  $X_lastname = $row['X'];
  $X_regdate = $row['X'];
  $X_ocupation = $row['X'];
  $X_gender = $row['X'];
  $X_main_proff = $row['X']; 

  if ($X_id == $id) { //the second is the SESSION ID
    $add_frined_button .= "";
  }
  else {
    $add_frined_button .= '&lt;tr&gt;
      &lt;td&gt;&lt;a href="#" onclick="return false" onmousedown="javascript:alertWindowFriend();"&gt;&lt;div class="submit_buttons_blue" id="add_friend"&gt;addfriend&lt;/div&gt;&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;';
  } 
</code></pre>

<p>This actually works good and the button handles the friend adding through jQuery and AJAX, but everything works wrong if I log with another user: </p>

<p>the ADD FRIEND button shows for him in the loop and although I made a check to see that, his session ID equals 2.<br />
When I send a friend request it shows as user with ID 2 requesting friendship from himself.</p>

<p>I really don't know what is the problem here, and if someone has a clue or needs to see more code like the friend request process, I will post it here.</p>
