I have created a site where people can create a profile. But I am trying to figure out how to start on making an add friend button so users can have friends.
In my user table, i have user_id, first_name, last_name, email, etc.
Should I somehow relate the user_id of the user and the friend in a friend table?
I am a novice to programming, so these things are still new to me. Thanks!
Well, let’s try to keep this simple.
You’re trying, essentially, to find a way to connect two users together.
Since I’m trying to keep things simple, and definitely not implying that this is the best way of doing it, I think the easiest way to go about doing this is to create a new table (users_friends) with the following fields: (user_id) and (friend_id).
Well, so let’s say my user_id is 5.
Your user_id is 10.
I want to add you as my friend, therefore I’d add an entry to that newly created table with the following values:
user_id = 5, friend_id = 10.
So, let’s say you want to display all of my friends, you could run a query such as:
Sure enough, removing a friend is easy, all you have to do is delete the entry from the newly created table …
And poof, you’re suddenly not my friend anymore 😉
So yeah, these are the basics.
I’d try this solution before moving on to a solution which will allow you more flexibility.