473,700 Members | 2,616 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Representing or determining "friend of a friend of a friend" relationships

FLEB
30 New Member
I'm working on a PHP/MySQL site with social networking and "message blast" functionality, and I'm not sure what the best method to represent multiple levels of interpersonal relationships in the database would be.

What I'd like to happen is this: A user posts a message to their page, with a "blast radius" option. The system then sends the message that many levels outward from the original person: A radius of 1 would go to their friends, a radius of 2 would go to their friends' friends, 3 goes to grand-friends, etc. I'm figuring that 3 levels would be the reasonable cut-off point-- I'm figuring that anything beyond that would involve sending the thing to the entire Internet.

(The "sending" isn't actually a duplication of the message-- merely an association of the message with the user that prompts it to be shown on the user's page.)

Now, I'm pretty green at database theory-- I'm more of a front-end and design guy-- so the only two options that come to my mind involve either a very large database or an extended hit on the database.

The first option would be to store every interpersonal relationship up to three levels deep in a table: The person's ID, The relation's ID, and the distance between the two (all integer identifiers). This would allow faster searching, since the distances are pre-calculated, and it's just a matter of getting anything relating to that particular person with a distance less than the blast radius.

The second option would be to only store immediate (distance=1) relationships, and make multiple queries, iterating through each friends' relationships, and each friends'-friends' relationships. This just sounds like a great way to choke a server, especially if it's being done often.

It sounds like the sort of problem that has been run into before, but I'm not sure what sort of terminology to search for-- is there a common solution to this problem?
Aug 24 '08 #1
1 2287
Atli
5,058 Recognized Expert Expert
Hi.

This sounds like a basic tree structure to me.
Like, say, if you had to expand a tree view in a directory browser, expanding from a give folder everything nested three directories down.

The basic thing is to create a recursive function or a nicely designed loop that iterates through the tree structure.

Like, say (in a PHP script):
Expand|Select|Wrap|Line Numbers
  1. function ScanDirectory($dirID, $depth=0, $maxdepth=3) 
  2. {
  3.   if($depth == $maxdepth) return;
  4.  
  5.   $sql = "SELECT DirID FROM DirTable WHERE ParentID = $dirID";
  6.   $result = mysqli_query($sql);
  7.  
  8.   while($row = mysqli_fetch_assoc($result)) {
  9.     for($i = 0; $i < $depth; $i++) echo " ";
  10.     echo $row['DirID'];
  11.  
  12.     ScanDirectory($row['DirID'], $depth + 1);
  13.   }
  14. }
  15.  
Which could result in something like
Expand|Select|Wrap|Line Numbers
  1. 1
  2.  4
  3.  5
  4.   10
  5. 2
  6.  6
  7.   8
  8.  7
  9.   11
  10. 3
  11.  9
  12.  
Aug 25 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3346
by: Erik T. Nomad | last post by:
I've created a link that will enable the reader of any page on my website to click it, enter an e-mail address, and have it arrive in that inbox with a hyperlink to the site. However, I'm wondering if there's a way to customize it further, such that the hyperlink they are sent is the web address of the page the "send to friend" link was on. I don't want to convert my entire site over to .asp, so having a pop-up .asp page seems to make...
2
9349
by: Shea Martin | last post by:
I am trying to use a system call which takes a function ptr. My compiler won't compile the code if I give the system_call a ptr to a class member function, A::func(). To combat this, I created an function, xfunc(A a), which wraps A::func(). For this to work properly, I need to make xfunc() a friend of class A. I am getting compile warnings regarding the system call being passed a function ptr, when it is expecting an extern "C"...
0
1256
by: zealotcat | last post by:
Code from book <<C++ templates>> ---------------------------------------------------- template<typename T> class C { .... friend void f(); friend void f(C<T> const&); .... };
43
2826
by: Zeng | last post by:
It's so messy w/o the "friend" relationship. Does anyone know why it was not supported in C#. It's almost about as bad as it doesn't support the inheritance hierarchy and method reference (calling tree) browsing that is supported in C++. I don't know how some could write a large scale object-oriented application w/o those. If you have overcome these limitations in C#, please share your thoughts and ideas. Thanks!
1
2233
by: timbobd | last post by:
I have encountered a situation that I don't understand. When I call a sub of Friend scope (in an object with Friend scope), I am getting an error "Public member 'subname' not found in type 'myType'". Any idea why? Since Friend scope should be visible within my assembly, and everying is taking place within a single project, I don't understand why this error is occuring. Here is some illustrative code, where I would get the error in the...
2
1556
by: Vark | last post by:
Interesting behavior I came across today where a child form has full access to a base form class' controls, but you can only modify the controls' properties in code, not in the visual designer. Here's how you can reproduce it: New Winforms project On Form1, drop a visual control. I'll use a panel in this example. Make sure Panel1 modifier is set to "Friend" Build project Add another form - this one an inherited form. Set it to inherit...
0
1616
by: AndyB | last post by:
I'm using xsd.exe to generate a typed-dataset. Then using typed dataset tables (datatables containing two columns--a name and a value) to bind to ASP.NET dropdown list controls (for the dropdown list option values). All was fine with the binding, until I moved the dataset to a different assembly, as I found out that the DataColumn property is "Friend" (in VB.NET). Could you point me how to make the DataColumn "public", or another work...
3
2263
by: jbeteta | last post by:
Hello, I have a problem declaring variables. I need to create an object oRpte as ReportClass on WebForm1.aspx and be able to use its value on WebForm2.aspx. For declaring the property oRpte() on WebForm1.aspx, I use "Public Property" and I declare variable _oRpte as Friend Shared. That's my problem. If I don't declare _oRpte as Friend Shared, I can't use WebForm1.oRpte() on other webpage. If I declare _oRpte as Friend Shared, I can use...
4
17075
by: Yarco | last post by:
In c++ we could modify the private variable in a class use friend keyword. How could it be done in php? class YourBag { int money; friend class Thief; // friend? };
0
8641
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9203
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9060
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7797
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6557
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2379
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2021
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.