adding friends in a while loop
===

i encountered a problem on my website, ill try to give as much details a s i can and would really appreciate your help!

so my problem started on the members page of my website where i used a while loop do display all member.

    $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) { //the second is the SESSION ID
    $add_frined_button .= "";
    }
    else {
    $add_frined_button .= '<tr>
         <td><a href="#" onclick="return false"    onmousedown="javascript:alertWindowFriend();"><div class="submit_buttons_blue" id="add_friend">addfriend</div></a></td>
      </tr>';
    } 


so this actually works good and the button handles the friend adding through jquery and ajax...BUT...

everything works wrong when i log with another user => the button of ADD FRIEND SHOWS for him in the loop and although i made a check to see that his session id equals 2 when i send a friend request it is shows as user with id 2 requesting friendship from himself.

i really dont know what is the problem here, and if someone has a clue or needs to see more codes like the friend request process i will post them here, thanks in advance to the helpers! :))