1
I have a table of friends, which has the following composition:
id_friends (id of the relation)
id_usuario_de (id of the user who sent the friend request)
id_usuario_para (id of the user who received the friend request)
id_status (whether the user who received the request accepted or not)
The whole system send/accept is ready, now I want to load a list of the logged user’s friends, in which I thought the following logic (using the same table).
If: the id_usuario_de
is the same as id_usuario
logated, bring the id_usuario_para
(who will be a friend of the logged in user)
Otherwise: if the id_usuario_para
is the same as id_usuario
logated, bring the id_usuario_de
(which will also be a friend of the logged in user, but it was he who sent the request).
I just need to bring the id_usuario
of the logged-in user friend, but I can’t/I have no idea how to do this with Mysql.
Thanks in advance for the help and I apologize if the question has become too confusing.
Edit
I got the expected result with the following consultation:
SELECT usuario.id_usuario, usuario.nome_completo, caminho, usuario.descricao FROM usuario, foto_usuario
WHERE (usuario.id_usuario
IN (SELECT id_usuario2 FROM amigos WHERE id_usuario1 = $usuario AND id_status = 8)
OR usuario.id_usuario
IN (SELECT id_usuario1 FROM amigos WHERE id_usuario2 = $usuario AND id_status = 8))
AND usuario.id_usuario != $usuario AND usuario.id_usuario = foto_usuario.id_usuario
But she got really big, I was wondering if there’s an "easy" way to make her...
PS:
- id_usuario1 = id_usuario_de, id_usuario2 = id_usuario_para
- In the query I get some extra data like photo and description
- The id_status = 8
is the id that signals that the relationship has been accepted, ie the id_usuario_para
accepted the request for friendship
Have you no starting point for the Mysql query? You can put this in your question?
– João Martins