We help IT Professionals succeed at work.

How to create a simple friends system?

evibesmusic asked
Last Modified: 2013-12-12
Hello all,

I know that this request is probablly not an easy one cause I am assuming that it woudl require the creation of some tables as well as a bit of php scripting


I would like to create a simple friends system like myspace for my site.  With that said, the amount of traffic on this site is minimal but, will grow with time.

Users should be able to: Add and Delete Friends, View Friend Requests, Deny Friend Requests, etc.

As I said, I know that this could be difficult but, if anyone had a starting point or a suggestion of where I could look to try and find a system that could do this, it would be most helpful.

Thank you very much...your guys are great!

Watch Question


ok, here is a rough idea.

Your friends table will be very simple -- two columns, id and friendid. Each pair will be a particular record. Suppose you have people named 1-5, and 2 and 3 are friends and 3 and 4 are friends

id   friendid
2    3
3    4

Since all friendships are mutual, you could list 3's friends with

SELECT * FROM friends WHERE id='3' OR friendid='3'

Next step is to make the requests table. This table is only needs to work one way, meaning that one person is the requestor and the other is the requestee. It would have the same format as the friends table.

Suppose 3 logs in, and 1 has recently requested to befriend him.

SELECT * FROM requests WHERE id=3

This will give one record response, and 3 can decide if he wants to be friends with 1. If yes, you make an entry in the friends table. In either case, you remove the request from the requests table.


I appologize about the last post...but, as listed...I am by no means a GURU on this subject.
I have read the post and understand the post above in theory but, it is in just that theory...

Can you explain how...if a new friend was added to the 'friends' database, that only has two colums (as stated above) would you be able to show multiple friends? Can you append the db using an UPDATE query so that each friend is recognized by an individual number aka friend id?

So I gues what I am asking is would the 'friendid' column's value look like this: 3,4,78,52 where each number represents a different friend?

Please let me know if I am making myself clear?

This one is on us!
(Get your first solution completely free - no credit card required)


Thank you for the response...I see what you are saying and have read the Wiki.

I was wondering if you have in your mind an order of things to do to get this project accomplished i.e.;
1. Create 'friends' db table
2. Create 'requests' db tabel
3. Create code to send requests
4. Create code to display friends
5. Create code to enable friend deletion...etc...

I know that their is always more than one way to skin a cat so if you have a better work flow that you think would get the job done could you please let me know?

Appreciate everything.


everything you have is good. You also need code to handle request acceptances and denials


O.k.  will take the next steps and report back with some questions, I'm sure.


Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.