This tutorial teaches you how to build a system whereby the users in your system can send friend request to other users in the system, those users who have been sent friend request have the options to accept or decline request sent to them depending on their choice of action using Ajax, Jquery and PHP.
This system works with MySql database and comprises of three tables.
The first table is where the details of the users in the system are stored and retrieved during Sign-up and Login process.
The second table is where the details of the users who are confirmed as friends are stored for friendship purpose.
The third table is where the details of every sent friend request are stored waiting for an acceptance or rejection by the user who the request was sent.
When a user sends a friend request by clicking on the Add as Friend button, this button will automatically change to Request Sent on successful sending of the request with an option to Cancel the sent request in case the user who sent the request wishes to stop the request.
Once a user who has been sent a friend request logs into the system or accesses the system, a notification for the request will be shown to this user from the top of the page with options to Accept the sent request or Decline the request depending on the user's choice of action.
If the user who has been sent a friend request chooses to accept the request, the request will be deleted from the Friends Request table and be stored in the Confirmed Friends table and both the user who sent the request and the user who the request was sent to will now see each other in their friends list.
If a user who has been sent a friend request chooses to decline the request, the request will be deleted from the Friends Request table and that ends the story. No further action is or will be taken.
This is a very simple to understand application that gives you the basics of how to implement this kind of systems with good programming code comments to ease usability.