[QUOTE=enzo420;1035568]OK
$rs = mysql_query("SELECT friends.*,users2.username,reqs.username AS requsername
from friends
LEFT JOIN users users2 ON friends.user = users2.id
LEFT JOIN users reqs ON friends.req = reqs.id WHERE confirmed = 1 AND (req = 1 OR `user` = 1)");
is user2 the users table? also is reqs supposed to be plural or do i copy the column name exactly?
cant get it to work :S
users2 is an alias for your 'users' table
reqs is another alias for your 'users' table
I have taken that your 'users' table has the following fields (amongst others):id (an autoincrement integer primary key)
username (varchar field holding user's handle)
Your 'friends' table, I have taken to have the following fields:
id (just an autoincrement integer primary key)
user (foreign key on id in the 'users' table)
req (foreign key on id in the 'users' table)
confirmed (0 = pending, 1 = confirmed)
The purpose of the sql is to link the 'friends.user' field (which is an user id) to the 'users.id' field and also link 'friends.req' field (which is also an user id) to the 'users.id' field. Thus we create two 'new' fields called 'username' and 'requsername'
For example:
users
id username
1 ardav
2 filo34
3 canzo
4 peeps456
5 costas
6 triage
7 carchaser
8 rugbyboy20
friends
id user req confirmed
1 1 8 1
2 1 6 1
3 2 1 1
4 3 1 0
5 2 3 1
6 4 8 1
if user '1' (ardav) is the focus, the recordset should output
id user req confirmed username requsername
1 1 8 1 ardav rugbyboy20
2 1 6 1 ardav triage
3 2 1 1 filo34 ardav
Your array (if taking the last example I posted), should be:
array(
array(8, 'rugbyboy20'),
array(6, 'triage'),
array(2, 'filo34')
)
I may have named some of your db fields or tables incorrectly, otherwise it should work.
for each array you could make links like this:
echo "<a href=\"profile.php?id={$fieldarray[$i][0]}\">{$fieldarray[$i][1]}</a>";
where $i is the counter in the loop.