0

Hello guys, I am doing a Friend system on my website, and I did the friend request, to accept, but the friends list isn't alright in some part of code because it isn't take the correct id, anyone can help me?

  1. <?php
  2. $users = $_SESSION['username'];
  3. $connect = mysql_connect("localhost","root","") or die(mysql_error());
  4. mysql_select_db("website");
  5. $user = $_GET['u'];
  6. $sql = mysql_query ("SELECT * FROM users");
  7. $result = mysql_fetch_assoc($sql);
  8. $id3 = $result['id'];
  9. $selusers = mysql_query("SELECT * FROM u_friends WHERE friend='$users' OR username='$users'");
  10. $row = mysql_num_rows($selusers);
  11. if($row!=0) {
  12. echo "<h1>Amigos</h1>";
  13. echo "<table align='center'>";
  14. while($rows = mysql_fetch_assoc($selusers)) {
  15. $id2 = $rows['id'];
  16. $read = $rows['accepted'];
  17. if($read==1)
  18. if(isset($_SESSION['username'])&&$_SESSION['username']!=($rows['username'])) {
  19. echo "<tr>";
  20. echo "<td>";
  21. echo "<a href='index.php?id=profile&u=".$id3."'>".$rows['username']."</a>";
  22. echo "</td>";
  23. echo "</tr>";
  24. } else if(isset($_SESSION['username'])&&$_SESSION['username']==($rows['username'])) {
  25. echo "<tr>";
  26. echo "<td>";
  27. echo "<a href='index.php?id=profile&u=".$id3."'>".$rows['friend']."</a>";
  28. echo "</td>";
  29. echo "</tr>";
  30. } else {
  31. echo "<table><tr><td>Não há utilizadores!</td></tr></table>";
  32. }
  33. echo "</table>";
  34. }
  35. }
  36. else {
  37. echo "<table><tr><td>Não há utilizadores!</td></tr></table>";
  38. }
  39. ?>

Anyone can help me please?When it says $id3, that's the problem

The error is when I put the echo "<a href='index.php?id=profile&u=".$id3."'>".$rows['friend']."</a>";

And the structures:

  1. TABLE users (
  2. id, int(11) NOT NULL AUTO_INCREMENT,
  3. username varchar(200) NOT NULL,
  4. password varchar(30) NOT NULL,
  5. email varchar(500) NOT NULL,
  6. repeatemail varchar(500) NOT NULL,
  7. country varchar(200) NOT NULL,
  8. gender varchar(60) NOT NULL,
  9. birthday varchar(60) NOT NULL,
  10. date date NOT NULL,
  11. random varchar(20) NOT NULL
  12. activated tinyint(1) NOT NULL DEFAULT
  13. PRIMARY KEY(id)
  14. )
  15. TABLE u_friends (
  16. id int(11) NOT NULL AUTO_INCREMENT,
  17. username varchar(200) NOT NULL,
  18. friend varchar(200) NOT NULL,
  19. date date NOT NULL,
  20. PRIMARY KEY(id)
  21. )
2
Contributors
2
Replies
31
Views
4 Years
Discussion Span
Last Post by nuno.freitas.meneses.monteiro
0

<a href='index.php?id=profile&u=".$id3."'>".$rows['username']."</a>
your $id3 is $result['id'] while the output value is $rows['username'].

May I know if users is the profile of the currently logged on user? I assume that u_friends is the user's friends list right?

sot the $id3 is came from users while $rows['username'] came from u_friends... they are really unrelated to each other

Edited by masterjiraya

0

Yes masterjiraya, you are right.
The users is the currently logged on user.

<a href='index.php?id=profile&u=".$id3."'>".$rows['username']."</a>

But if you but $rows['username'] it will appears the user will pick the username at the database u_friends and I want to pick the friends row.

Edited by nuno.freitas.meneses.monteiro

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.