If someone can help me with this issue I have I’ll appreciate it SO MUCH!
I’m making a website where I want registered users to be able to add each other as friends.
The person must “invite” another registered user (on the database). The other person will receive a notification of some sort. If the person ignores the notification, nothing happens and when he/she approves, they are friends.
Now I have a idea with the table I’m going to use:
+----------------------------------------+
| Requests |
+----------------------------+-----------+
| id | user_from | user_to | status |
+----+-----------+-----------+-----------+
| | | | |
| | | | |
| | | | |
| | | | |
+----------------------------+-----------+
As I said this is only an idea I want to use but I don’t know what the code will be in the php when I have a link to add a person as a friend.
I think the admin to approve of the request sent and when the user approves or not. I don’t know how that table will look.
And I thought about using INNER JOIN to “join” the two users as friends. BUT again, not completely sure how to go about that. Will this come in my php? Lets say friends.php?
SELECT name, email FROM users
INNER JOIN friends ON users.id = friends.user.id WHERE users.id = 1
As I said, I have a good idea of what to do but when it comes to coding it, I’m not completely sure how to do that…
Thanks!
You should have a relationships table that simply associates user.id’s.
Where user_id1 and user_id2 are both user.id. Note: I’d probably make status be an enum, with something like ‘pending, declined, friend, enemy’. I initially thought of using a bool, but what if there is some other desired status later on? Like maybe you keep track of broken friendships, or some other kind of relation.
Then you simply do a multiple where clause to determine friends:
WHERE (user_id=:id OR friend_id=:id) AND status='friend'