Friends and Relationships Relationships Our relationships table needs to relate two users together, as well as record the type of relationship. Since some relationships require mutual consent, we need to indicate if the non-requesting user accepted the request to connect. The following is a suitable structure for our relationships table: Field ID Type Usera Userb Accepted Type Integer, Primary Key, Auto Increment ID Integer Integer Boolean Description A unique ID for the relationship between the two users The type of relationship (a reference to the relationship_types table) The user who initiated the relationship, a relation to the users table The user who usera. | Friends and Relationships Relationships Our relationships table needs to relate two users together as well as record the type of relationship. Since some relationships require mutual consent we need to indicate if the non-requesting user accepted the request to connect. The following is a suitable structure for our relationships table Field TyPe Description ID Integer Primary Key Auto Increment A unique ID for the relationship between the two users TyPe ID The type of relationship a reference to the relationship_types table Usera Integer The user who initiated the relationship a relation to the users table Userb Integer The user who usera initiated a relationship with a relation to the users table Accepted Boolean Indicates if this is a mutual relationship which is only used if the relationship type is a mutual relationship Adding friends Our users can see other users on the site either by searching for them or viewing a list of users from here we can add a link to enable the user to form a relationship. We have a suitable database structure to facilitate this but we now need functionality to connect our users together. Forming a relationship Let s walk through what the process should be for our users to form relationships with each other 1. View the listing of the user they wish to connect with. 2. Click on a link or select a relationship type from a list and click on Submit. 3. Check for pre-existing relationships. 4. Check if the relationship type selected is active. 5. Create the relationship in the database. 122 Download from Chapter 4 6. If the relationship type is mutual e-mail the other user an approval request message asking them to confirm the relationship. 7. If the relationship type isn t mutual e-mail the other user a message informing them that someone has connected with them. We already have step one set up the list of members. For step two we either need a link on the user s name or a list of relationship types which are links or .