hi,

im working on a project where i need to create a relation graph......
Given one user's id as input i need to fetch all his contacts and contacts of all his contacts and contacts of his contacts of contacts.....

so i need 3 levels of contacts or u could say to make it better n levels of contacts.

once i get all this information into a datastructure i need to draw a graph which has an edge between all the users who are contacts of each other. also note that the contact relationship is unidirectional meaning if A is a contact of B then its not necesarry that B is a contact of A.

right now i am working with array and i dont think thats the way to go because what happens is when i i get 1 level of contacts then there is a huge probability that one user can be a contact of more than one person thus i get a lot of redundant data....

i know i need to use classes but i cant figure out how i can make an array of objects.... below is the code that i have written so far... i have an idea but donot know how to implement..

require_once("phpFlickr.php");
$f = new phpFlickr("555013b682d0a671e42aba02d3be989d");

class contact_user
{

public:
var $nsid;
var $flag;

contact_user($id)
{
	$flag=false;
	$nsid=$id;
}
}//end of class contact_user




$contact = $f->contacts_getPublicList("28890953@N07");
$obj = new contact_user("28890953@N07");



foreach($contact['contact'] as $newarray)
{

$array_nsid['28890953@N07'][]=$newarray['nsid'];
$array_username['28890953@N07'][]=$newarray['username'];

$value=$newarray['nsid'];


$set[$value]['flag']="false";
$contact_level2 = $f->contacts_getPublicList($value);


	foreach($contact_level2['contact'] as $newarray2)
	{
		$set[$value]['flag']="true";
		$array_nsid[$value][]=$newarray2['nsid'];
		$array_username[$value][]=$newarray2['username'];

		$value2=$newarray2['nsid'];

		$contact_level3 = $f->contacts_getPublicList($value2);

			foreach($contact_level3['contact'] as $newarray3)
			{
					$array_nsid[$value2][]=$newarray3['nsid'];
					$array_username[$value2][]=$newarray3['username'];
			}//closing of inner most foreach



	}//closing of level 2 foreach


}//closing of outermost for each
echo "<pre>";
print_r($array_nsid);
echo "</pre>";
echo "<pre>";
print_r($array_username);
echo "</pre>";
echo "</td></td></table>";
?>

    I'd make 2 objects: 1) A user object which holds user information, and 2) a connections object which relates user object instances together. Then you'll only have 1 instance of each user.

    Now, I'd be more concerned about memory -- loading a lot of people and the relationships together will require a bit of memory. Are you doing something to manage that while creating your graph?

      Write a Reply...