Using Example 20-10, rnmembers.php, your users will be able to find other members and choose to add them as friends (or drop them if they are already friends). This program has two modes. The first lists all members and their relationships to you, and the second shows a user’s profile.
The code for the latter mode comes first, where a test is made
'view'. If it exists, a user wants to view
someone’s profile, so the program does that using the
showProfile function, along with providing a
couple of links to the user’s friends and messages.
After that the two
'remove' are tested. If one or the other has
a value, it will be the username of a user to either add or drop as a
friend. This is achieved by looking the user up in the MySQL
rnfriends table and either inserting a
friend username or removing it from the table.
And, of course, every posted variable is first passed through
sanitizeString to ensure it is safe
to use with MySQL.
The final section of code issues a SQL query to list all
usernames. The code places the number returned in the variable
$num before outputting the page
for loop then iterates
through each and every member, fetching their details and then looking
them up in the
rnfriends table to see if they are either being followed by or a follower of the user. If someone is both a follower and a followee, they are classed as a mutual friend. ...