RE: [PHP-DB] Help needed creating a social network

From: Date: Wed, 08 Mar 2006 03:24:14 +0000
Subject: RE: [PHP-DB] Help needed creating a social network
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-41403@lists.php.net to get a copy of this message
My first thought was recursion - repeat the call for each element of the result set, numbering each so you can find each level, until nothing is returned. That would probably work, but oh, what a mess. That triggered something ... off to consult Joe Celko's SQL for Smarties. He has a whole chapter on Trees, and guess what: they're not easily done in relational databases. To try and condense it here would be, shall we say, impractical. Check with a library, or try googling for trees -- hey, look what turned up:
        http://www.dbmsmag.com/9603d06.html
by JC himself. Have fun - Miles Thompson At 03:19 PM 3/7/2006, Daevid Vincent wrote:
Thanks for the reply. However, that only gives me a single degree. I'm looking for the way to traverse a 'tree' to see who is in your extended networks, so I can do things like: You are 4 degrees away from Sam: You know bob who knows john who knows carrol who knows Sam. Sam <- carrol <- john <- bob <- you Etc. -----Original Message----- From: Micah Stevens [mailto:micah@raincross-tech.com] Sent: Monday, March 06, 2006 10:28 PM To: php-db@lists.php.net Subject: Re: [PHP-DB] Help needed creating a social network CREATE TABLE users (userID int(11) not null auto_increment, primary key(userID), name tinytext not null, email tinytext not null); CREATE TABLE links (userID int(11), key (userID), friendID int(11), key(friendID)); <?php $friends = mysql_query("select users.name, users.userID from users left join links on links.friendID = users.userID where links.userID = {$_GET['userID']}"); echo "<h1>You have friends!!</h1>"; while ($f = mysql_fetch_assoc($friends)) { echo "<a href='socialnetwork.php?userID={$f['userID']}'>{$f['name']}</a
<br>\n";
} publish(); profit($greatly); do (!$use) {
      coldfusion('Cause it sucks');
} ?> (har har) On Monday 06 March 2006 9:47 pm, Daevid Vincent wrote:
Anyone have some pointers at a HowTo on creating a social network? Basically I need to show people in your immediate network,
and also friends
of your friends, etc... Like the whole 'six degrees of
separation' thing.
Ala: myspace, friendster, etc. ad nauseum. I prefer mySQL and PHP, but I could port from most any
code. I guess I'm
mostly interested in the theory of this an how do I set up
the tables
properly and what is the magic incantation (JOIN) to get
this "chain" of
people.
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.1.375 / Virus Database: 268.2.0/275 - Release Date: 3/6/2006

« previous php.db (#41403) next »