Family Tree code :Help needed
Posted: Mon Oct 18, 2004 5:34 am
feyd | Help us, help you. Please use
feyd | Help us, help you. Please use
Code: Select all
andCode: 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
andCode: 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]