Family Tree code :Help needed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
just_ht
Forum Newbie
Posts: 12
Joined: Mon Oct 18, 2004 5:24 am
Contact:

Family Tree code :Help needed

Post by just_ht »

feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I need to implement  simple Family Tree  ,Taking value from DB(Mysql)
I need to implement it for as many level as..,
Any Idea lease help

here is code:

Code: Select all

<? 
/* 
Input this in your mySql db  before running this 
it allows you to get 99 heads  and  1--99  categorie in each node 
Warning code only 3 levels, need to improve it
# Table structure for table 'res_cat' 
CREATE TABLE res_cat ( 
   ID int(32) DEFAULT '0' NOT NULL , 
   ID_uname char(40) NOT NULL, 
   UNIQUE ID (ID) 
); */

# Dumping data for table 'res_cat'
$mysql_link = mysql_connect("localhost", " username", " password"); 
mysql_select_db("res_cat", $mysql_link); 
echo "<html><body>" ; 

function listrub ($id , $exploseID   ) 
{ 
global $PHP_SELF ; 
global $mysql_link  ; 
$maxi = ($id*100)+100 ; 
$mini = $id*100 ; 
$query = "SELECT * FROM res_cat  where ID < $maxi and ID >  $mini    " ;

echo "<ol>"; 
if(      $mysql_result = mysql_query($query , $mysql_link)   ) 
{ 
while ($row = mysql_fetch_object($mysql_result)) 
    { 
// you have to link some action on leaves of course 
echo "<li> <a href='$PHP_SELF?ID_rub=$row->ID' >   $row->ID_uname </a>  </li> " ; 
$testID = ($exploseID - ($exploseID  %100 ))/100 ; //  WARNING this is ugly .. only 3 level
if ( $testID == $row->ID || $exploseID == $row->ID) 
         { 
         listrub ($row->ID , $exploseID ) ; 
        } 
    } 
} 
echo "</ol>"; 
} 
$father =999999999;  // a big number   
// get the grand...grand father 
if ( $ID_rub >100 ) 
{ 
$father = $ID_rub ; 
while ( $father >100 )    { $father= ( $father - ( $father %100) )/100 ; } 
} 
else{$father= $ID_rub ;} 
listrub ($father , $ID_rub ,$mysql_link ) ;   
echo "</body></html>"; 

?>

feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Sema
Forum Commoner
Posts: 34
Joined: Fri Sep 03, 2004 12:43 pm
Location: Aalborg, Denmark

Post by Sema »

hmm i know that the admins/mods will tell you this, but you need to use the -

Code: Select all

  [/php ]- tags around your code in this forum, it is better for the users of the forum...  :P
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

also, why do u only post some of the code in each reply? :S
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

for future reference, there wasn't a need to have 4 posts just for the code.

As for your "problem", as vague as it is, recursion is one basic way to do it. it looks like you have the beginnings of how to do it, but will likely run out of memory quickly. This may be a bit complicated for a beginner to be working on. Maybe you can figure out a different way.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

shouldn't be to hard to type "tree in sql" in a search engine.

pretty sure you will find thingies like nested sets etc.... even this forum has quite some threads on the issue...
just_ht
Forum Newbie
Posts: 12
Joined: Mon Oct 18, 2004 5:24 am
Contact:

Post by just_ht »

Thanks for all that stuff,I think I got some basic idea to do it now but it will be really helpful if any one can
provide some code snippets to sort out the problem.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

one of ways I've done this sort of thing in the past is through parsing the current level before any sublevels. Whenever I came across a level that had sublevels I stored off a reference to that level in another array that I used as a level list of sorts.

This is very similar to doing recursive directory/folder traversal.
just_ht
Forum Newbie
Posts: 12
Joined: Mon Oct 18, 2004 5:24 am
Contact:

Post by just_ht »

hELLO fEYD

>one of ways I've done this sort of thing in the past is through parsing the current level before any sublevels. Whenever I came across a level that had sublevels I stored off a reference to that level in another array that I used as a level list of sorts

>>cAN U PLEASE POST THE CODE; THANKS IN ADVANCE
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I won't, because I feel you should be able to figure this out on your own with some tips from us, among others...
Post Reply