Ok, we’ve created our fancy login system for our site. Now what? How do my members intereact with each other? This bring us back over 5 years ago when MySpace.com first debuted. Every web programmer on earth went “gaga” over how such a simple method used for “friending” another member became so big! Today we have sites like friendster, facebook, and orkut that use the same theory behind virtually friending your friends!
Here’s how they do it:
If Member1 wants to friend Member2, a request is made via a link or action on Member1’s part.
Using a relational database, this is what this request will look like.
Member’s Table (this contains all of our members, it may also contain other information like name, password, and other profile information.)
memberID 1 2
Friend’s Table (This table is updated whenever a member invokes a “friending” action.)
memberID friendID Confirmed 2 1 0
When the member represented by the “friendID” confirms that they would in fact want to be friends with the member represented by “memberID,” then “Confirmed” will be updated to “1″ in place of “0.”
So now, our scripts will have a way to tell if one member is friends with another, how many friends any given member has, how many requests for friends a given member has.
MySQL Snippet for querying the number of friends of a given member
SELECT count(*) FROM Friends WHERE memberID = 1 AND Confirmed > 0;
Comments»
Hack the planet!
thanks for the sql snippet! I was going to “roll my own” social networking software, but I ended up going with PHPizabi, even though it’s in beta. I’m constantly attempting to get an online networking community for the Naples, FL area but it’s hard. You never know what google will pick up! Check out http://naplesnerds.com and let’s give us nerds a place to go.